Skip to content

Commit 5e1adfe

Browse files
authored
feat: 🎸 Improve code quality and support PHPStan (#14)
1 parent 8508020 commit 5e1adfe

39 files changed

+889
-185
lines changed

.github/workflows/ci.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
2525
strategy:
2626
matrix:
27-
php: [7.3, 7.4, '8.0', 8.1]
27+
php: [7.4, '8.0', 8.1]
2828
lib:
2929
- { laravel: ^9.0 }
3030
- { laravel: ^8.0 }
@@ -36,7 +36,11 @@ jobs:
3636
- { php: 8.1, lib: { laravel: ^6.0 } }
3737
- { php: 8.1, lib: { laravel: ^6.0, flags: --prefer-lowest } }
3838
- { php: 7.4, lib: { laravel: ^9.0 } }
39-
- { php: 7.3, lib: { laravel: ^9.0 } }
39+
include:
40+
- { php: 8.1, lib: { laravel: ^9.0 }, phpstan: '1' }
41+
- { php: 8.1, lib: { laravel: ^8.0 }, phpstan: '1' }
42+
- { php: '8.0', lib: { laravel: ^9.0 }, phpstan: '1' }
43+
- { php: '8.0', lib: { laravel: ^8.0 }, phpstan: '1' }
4044

4145
steps:
4246
- uses: actions/checkout@v2
@@ -51,6 +55,10 @@ jobs:
5155
run: |
5256
composer require "laravel/framework:${{ matrix.lib.laravel }}" --dev ${{ matrix.lib.flags }}
5357
58+
- name: PHPStan
59+
if: ${{ matrix.phpstan }}
60+
run: composer phpstan
61+
5462
- run: mkdir -p build/logs
5563
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
5664

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
composer.lock
2+
/.idea/
23
/vendor/
34
/build/logs/
45
.php_cs.cache

.scrutinizer.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ checks:
44

55
filter:
66
excluded_paths:
7+
- phpstan/*
78
- tests/*
89
- vendor/*
910

@@ -14,12 +15,6 @@ build:
1415
tests:
1516
override:
1617
- php-scrutinizer-run
17-
18-
environment:
19-
php: '7.4'
20-
docker: true
21-
22-
nodes:
2318
custom-nodes:
2419
services:
2520
custom-mysql:
@@ -32,6 +27,10 @@ build:
3227
ports:
3328
- 3306
3429

30+
environment:
31+
php: '7.4'
32+
docker: true
33+
3534
dependencies:
3635
before:
3736
- composer install

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ A tiny extension of `MySqlConnection` that manages **session** system variables
44

55
## Requirements
66

7-
- PHP: `^7.3 || ^8.0`
8-
- Laravel: `^6.0 || ^7.0 || ^8.0 || ^9.0`
7+
| Package | Version | Mandatory |
8+
|:---|:---|:---:|
9+
| PHP | <code>^7.4 &#124;&#124; ^8.0</code> ||
10+
| Laravel | <code>^6.0 &#124;&#124; ^7.0 &#124;&#124; ^8.0 &#124;&#124; ^9.0</code> ||
11+
| PHPStan | <code>&gt;=1.1</code> | |
912

1013
## Installing
1114

_ide_helper.php

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
namespace Illuminate\Database
4+
{
5+
if (false) {
6+
interface ConnectionInterface
7+
{
8+
/**
9+
* Set MySQL system variable for both read and write PDOs.
10+
* It is lazily executed for unresolved PDO instance.
11+
*
12+
* @param mixed $value
13+
* @return $this
14+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
15+
*/
16+
public function setSystemVariable(string $key, $value, bool $memoizeForReconnect = true);
17+
18+
/**
19+
* Set MySQL system variables for both read and write PDOs.
20+
* It is lazily executed for unresolved PDO instance.
21+
*
22+
* @param array $values
23+
* @param bool $memoizeForReconnect
24+
* @return $this
25+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
26+
*/
27+
public function setSystemVariables(array $values, bool $memoizeForReconnect = true);
28+
29+
/**
30+
* Run callback temporarily setting MySQL system variable for both read and write PDOs.
31+
* It is lazily executed for unresolved PDO instance.
32+
*
33+
* @param mixed $value
34+
* @param mixed ...$args
35+
* @return mixed
36+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
37+
*/
38+
public function usingSystemVariable(string $key, $value, callable $callback, ...$args);
39+
40+
/**
41+
* Run callback temporarily setting MySQL system variables for both read and write PDOs.
42+
* It is lazily executed for unresolved PDO instance.
43+
*
44+
* @param array $values
45+
* @param mixed ...$args
46+
* @return mixed
47+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
48+
*/
49+
public function usingSystemVariables(array $values, callable $callback, ...$args);
50+
}
51+
52+
class Connection implements ConnectionInterface
53+
{
54+
/**
55+
* Set MySQL system variable for both read and write PDOs.
56+
* It is lazily executed for unresolved PDO instance.
57+
*
58+
* @param mixed $value
59+
* @return $this
60+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
61+
*/
62+
public function setSystemVariable(string $key, $value, bool $memoizeForReconnect = true)
63+
{
64+
}
65+
66+
/**
67+
* Set MySQL system variables for both read and write PDOs.
68+
* It is lazily executed for unresolved PDO instance.
69+
*
70+
* @param array $values
71+
* @param bool $memoizeForReconnect
72+
* @return $this
73+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
74+
*/
75+
public function setSystemVariables(array $values, bool $memoizeForReconnect = true)
76+
{
77+
}
78+
79+
/**
80+
* Run callback temporarily setting MySQL system variable for both read and write PDOs.
81+
* It is lazily executed for unresolved PDO instance.
82+
*
83+
* @param mixed $value
84+
* @param mixed ...$args
85+
* @return mixed
86+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
87+
*/
88+
public function usingSystemVariable(string $key, $value, callable $callback, ...$args)
89+
{
90+
}
91+
92+
/**
93+
* Run callback temporarily setting MySQL system variables for both read and write PDOs.
94+
* It is lazily executed for unresolved PDO instance.
95+
*
96+
* @param array $values
97+
* @param mixed ...$args
98+
* @return mixed
99+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
100+
*/
101+
public function usingSystemVariables(array $values, callable $callback, ...$args)
102+
{
103+
}
104+
}
105+
}
106+
}
107+
108+
namespace Illuminate\Support\Facades
109+
{
110+
if (false) {
111+
class DB extends Facade
112+
{
113+
/**
114+
* Set MySQL system variable for both read and write PDOs.
115+
* It is lazily executed for unresolved PDO instance.
116+
*
117+
* @param mixed $value
118+
* @return \Illuminate\Database\Connection
119+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
120+
*/
121+
public static function setSystemVariable(string $key, $value, bool $memoizeForReconnect = true)
122+
{
123+
}
124+
125+
/**
126+
* Set MySQL system variables for both read and write PDOs.
127+
* It is lazily executed for unresolved PDO instance.
128+
*
129+
* @param array $values
130+
* @param bool $memoizeForReconnect
131+
* @return \Illuminate\Database\Connection
132+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
133+
*/
134+
public static function setSystemVariables(array $values, bool $memoizeForReconnect = true)
135+
{
136+
}
137+
138+
/**
139+
* Run callback temporarily setting MySQL system variable for both read and write PDOs.
140+
* It is lazily executed for unresolved PDO instance.
141+
*
142+
* @param mixed $value
143+
* @param mixed ...$args
144+
* @return mixed
145+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
146+
*/
147+
public static function usingSystemVariable(string $key, $value, callable $callback, ...$args)
148+
{
149+
}
150+
151+
/**
152+
* Run callback temporarily setting MySQL system variables for both read and write PDOs.
153+
* It is lazily executed for unresolved PDO instance.
154+
*
155+
* @param array $values
156+
* @param mixed ...$args
157+
* @return mixed
158+
* @see \Mpyw\LaravelMySqlSystemVariableManager\ManagesSystemVariables
159+
*/
160+
public static function usingSystemVariables(array $values, callable $callback, ...$args)
161+
{
162+
}
163+
}
164+
}
165+
}

composer.json

+21-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"keywords": ["laravel", "illuminate", "mysql", "system", "variable"],
1313
"autoload": {
1414
"psr-4": {
15-
"Mpyw\\LaravelMySqlSystemVariableManager\\": "src/"
15+
"Mpyw\\LaravelMySqlSystemVariableManager\\": "src/",
16+
"Mpyw\\LaravelMySqlSystemVariableManager\\PHPStan\\": "phpstan/"
1617
}
1718
},
1819
"autoload-dev": {
@@ -21,18 +22,32 @@
2122
}
2223
},
2324
"require": {
24-
"php": "^7.3 || ^8.0",
25+
"php": "^7.4 || ^8.0",
2526
"ext-pdo": "*",
2627
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0",
2728
"illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0",
28-
"mpyw/unclosure": "^1.0",
29-
"mpyw/laravel-pdo-emulation-control": "^1.0"
29+
"mpyw/unclosure": "^3.0",
30+
"mpyw/laravel-pdo-emulation-control": "^2.0.2"
3031
},
3132
"require-dev": {
3233
"orchestra/testbench": "*",
3334
"orchestra/testbench-core": "^4.9 || ^5.9 || >=6.6",
34-
"phpunit/phpunit": ">=9.5"
35+
"phpunit/phpunit": ">=9.5",
36+
"phpstan/phpstan": ">=1.1",
37+
"phpstan/extension-installer": ">=1.1",
38+
"nunomaduro/larastan": "^1.0"
39+
},
40+
"scripts": {
41+
"test": "vendor/bin/phpunit",
42+
"phpstan": "vendor/bin/phpstan analyse src tests phpstan"
3543
},
3644
"minimum-stability": "dev",
37-
"prefer-stable": true
45+
"prefer-stable": true,
46+
"extra": {
47+
"phpstan": {
48+
"includes": [
49+
"extension.neon"
50+
]
51+
}
52+
}
3853
}

extension.neon

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
-
3+
class: Mpyw\LaravelMySqlSystemVariableManager\PHPStan\ConnectionClassExtension
4+
tags:
5+
- phpstan.broker.methodsClassReflectionExtension
6+
-
7+
class: Mpyw\LaravelMySqlSystemVariableManager\PHPStan\CallableReturnTypeExtension
8+
tags:
9+
- phpstan.broker.dynamicMethodReturnTypeExtension
10+
-
11+
class: Mpyw\LaravelMySqlSystemVariableManager\PHPStan\CallableFacadeReturnTypeExtension
12+
tags:
13+
- phpstan.broker.dynamicStaticMethodReturnTypeExtension

phpstan.neon

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
includes:
2+
- ./extension.neon
3+
4+
parameters:
5+
level: 9
6+
checkMissingIterableValueType: false
7+
reportUnmatchedIgnoredErrors: false
8+
ignoreErrors:
9+
- message: '#Cannot access property \$value on mixed#'
10+
path: tests

phpstan/CallableArgumentParameter.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Mpyw\LaravelMySqlSystemVariableManager\PHPStan;
4+
5+
use PHPStan\Reflection\ParameterReflection;
6+
use PHPStan\Reflection\PassedByReference;
7+
use PHPStan\Type\MixedType;
8+
use PHPStan\Type\Type;
9+
10+
final class CallableArgumentParameter implements ParameterReflection
11+
{
12+
public function getName(): string
13+
{
14+
return 'args';
15+
}
16+
17+
public function isOptional(): bool
18+
{
19+
return false;
20+
}
21+
22+
public function getType(): Type
23+
{
24+
return new MixedType();
25+
}
26+
27+
public function passedByReference(): PassedByReference
28+
{
29+
return PassedByReference::createNo();
30+
}
31+
32+
public function isVariadic(): bool
33+
{
34+
return false;
35+
}
36+
37+
public function getDefaultValue(): ?Type
38+
{
39+
return null;
40+
}
41+
}

0 commit comments

Comments
 (0)