Skip to content

Commit e11ce9f

Browse files
committed
feature: add basic stub for config helper
1 parent f193724 commit e11ce9f

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

stubs/helpers.stubphp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,14 @@ function logger($message = null, array $context = [])
116116

117117
return app('log')->debug($message, $context);
118118
}
119+
120+
/**
121+
* Get / set the specified configuration value.
122+
*
123+
* If an array is passed as the key, we will assume you want to set an array of values.
124+
*
125+
* @param array<string, mixed>|string|null $key
126+
* @param mixed $default
127+
* @return ($key is null ? \Illuminate\Config\Repository : ($key is array ? null : mixed))
128+
*/
129+
function config($key = null, $default = null) {}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Feature: Config helper
2+
The global config helper will return a strict type
3+
4+
Background:
5+
Given I have the following config
6+
"""
7+
<?xml version="1.0"?>
8+
<psalm errorLevel="1">
9+
<projectFiles>
10+
<directory name="."/>
11+
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
12+
</projectFiles>
13+
<plugins>
14+
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
15+
</plugins>
16+
</psalm>
17+
"""
18+
And I have the following code preamble
19+
"""
20+
<?php declare(strict_types=1);
21+
"""
22+
23+
Scenario: config with no arguments returns a repository instance
24+
Given I have the following code
25+
"""
26+
function test(): \Illuminate\Config\Repository {
27+
return config();
28+
}
29+
"""
30+
When I run Psalm
31+
Then I see no errors
32+
33+
Scenario: config with one argument
34+
Given I have the following code
35+
"""
36+
/**
37+
* @return mixed
38+
*/
39+
function test()
40+
{
41+
return config('app.name');
42+
}
43+
"""
44+
When I run Psalm
45+
Then I see no errors
46+
47+
Scenario: config with first null argument and second argument provided
48+
Given I have the following code
49+
"""
50+
/**
51+
* @return mixed
52+
*/
53+
function test()
54+
{
55+
return config('app.non-existent', false);
56+
}
57+
"""
58+
When I run Psalm
59+
Then I see no errors
60+
61+
Scenario: config setting at runtime
62+
Given I have the following code
63+
"""
64+
/**
65+
* @return null
66+
*/
67+
function test()
68+
{
69+
return config(['app.non-existent' => false]);
70+
}
71+
"""
72+
When I run Psalm
73+
Then I see no errors

0 commit comments

Comments
 (0)