Skip to content

Commit 48c4d3b

Browse files
committed
Merge branch 'cleanup'
2 parents 863b953 + 95e2127 commit 48c4d3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1037
-1483
lines changed

.vscode/php.code-snippets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"body": [
66
"<?php declare(strict_types=1);",
77
"",
8-
"namespace ${TM_DIRECTORY/^.*\\\\/src\\\\/(Toolkit|(Sli))|^.*\\\\/(tests\\\\/(?:unit|fixtures|3rdparty)\\\\/(Toolkit|(Sli)))|\\\\/([a-zA-Z0-9]+)/${1:+Salient}${2:+\\\\Sli}${4:+Salient}${3:+\\\\Tests}${5:+\\\\Sli}${6:+\\\\}$6/g};",
8+
"namespace ${TM_DIRECTORY/^.*\\\\/src\\\\/(Toolkit|(Sli|PHPStan))|^.*\\\\/(tests\\\\/(?:unit|fixtures|3rdparty)\\\\/(Toolkit|(Sli|PHPStan)))|\\\\/([a-zA-Z0-9]+)/${1:+Salient}${2:+\\\\}$2${4:+Salient}${3:+\\\\Tests}${5:+\\\\}$5${6:+\\\\}$6/g};",
99
"",
1010
"${RELATIVE_FILEPATH/(?:.*(?:(\\\\/Contract\\\\/.*|Interface\\.php$)|(\\\\/Concern\\\\/.*|Trait\\.php$))|(^(?:.(?!\\\\/(?:Contract|Concern)\\\\/|(?:Interface|Trait)\\.php$))*$))/${1:+interface}${2:+trait}${3:+class}/} ${TM_FILENAME_BASE/[^a-zA-Z0-9]+//g} {",
1111
" $0",
@@ -17,7 +17,7 @@
1717
"scope": "php",
1818
"prefix": "namespace",
1919
"body": [
20-
"namespace ${TM_DIRECTORY/^.*\\\\/src\\\\/(Toolkit|(Sli))|^.*\\\\/(tests\\\\/(?:unit|fixtures|3rdparty)\\\\/(Toolkit|(Sli)))|\\\\/([a-zA-Z0-9]+)/${1:+Salient}${2:+\\\\Sli}${4:+Salient}${3:+\\\\Tests}${5:+\\\\Sli}${6:+\\\\}$6/g};"
20+
"namespace ${TM_DIRECTORY/^.*\\\\/src\\\\/(Toolkit|(Sli|PHPStan))|^.*\\\\/(tests\\\\/(?:unit|fixtures|3rdparty)\\\\/(Toolkit|(Sli|PHPStan)))|\\\\/([a-zA-Z0-9]+)/${1:+Salient}${2:+\\\\}$2${4:+Salient}${3:+\\\\Tests}${5:+\\\\}$5${6:+\\\\}$6/g};"
2121
]
2222
}
2323
}

composer.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
"adodb/adodb-php": "Required for access to databases",
3131
"league/oauth2-client": "Required for integration with OAuth 2.0 service providers",
3232
"firebase/php-jwt": "Required for validation of OAuth 2.0 access tokens",
33-
"analog/analog": "Allows Analog handlers to be used as console message targets",
34-
"clue/phar-composer": "Simplifies creation of phar archives"
33+
"analog/analog": "Allows Analog handlers to be used as console message targets"
3534
},
3635
"require-dev": {
3736
"adodb/adodb-php": "^5",
3837
"analog/analog": "^1",
39-
"clue/phar-composer": "^1",
4038
"ergebnis/phpunit-slow-test-detector": "^2",
4139
"firebase/php-jwt": "^6",
4240
"league/oauth2-client": "^2",
@@ -66,6 +64,8 @@
6664
"autoload-dev": {
6765
"psr-4": {
6866
"Salient\\Sli\\": "src/Sli/",
67+
"Salient\\PHPStan\\": "src/PHPStan/",
68+
"Salient\\Tests\\PHPStan\\": "tests/unit/PHPStan/",
6969
"Salient\\Tests\\": [
7070
"tests/unit/Toolkit/",
7171
"tests/fixtures/Toolkit/",
@@ -85,5 +85,12 @@
8585
"allow-plugins": {
8686
"phpstan/extension-installer": true
8787
}
88+
},
89+
"extra": {
90+
"phpstan": {
91+
"includes": [
92+
"phpstan.extension.neon"
93+
]
94+
}
8895
}
8996
}

phpstan-baseline-7.4.neon

Lines changed: 7 additions & 307 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline-8.3.neon

Lines changed: 3 additions & 303 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.extension.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
services:
2+
-
3+
class: Salient\PHPStan\Core\Utility\Str\MethodReturnTypeExtension
4+
tags:
5+
- phpstan.broker.dynamicStaticMethodReturnTypeExtension
6+
7+
-
8+
class: Salient\PHPStan\Core\Utility\Get\MethodReturnTypeExtension
9+
tags:
10+
- phpstan.broker.dynamicStaticMethodReturnTypeExtension

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
includes:
2+
- phpstan.extension.neon
23
- tests/phpstan-conditional.php
34

45
parameters:

scripts/generate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
Config::class => [ConfigurationManager::class, '--api'],
7070
Console::class => [ConsoleWriter::class, '--api'],
7171
Err::class => [ErrorHandler::class, '--skip', 'handleShutdown,handleError,handleException'],
72-
Event::class => EventDispatcher::class,
72+
Event::class => [EventDispatcher::class, '--api'],
7373
Sync::class => SyncStore::class,
7474
Profile::class => [MetricCollector::class, '--api'],
7575
// Test fixtures
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\PHPStan\Core\Utility\Get;
4+
5+
use PhpParser\Node\Expr\StaticCall;
6+
use PHPStan\Analyser\Scope;
7+
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
9+
use PHPStan\Type\NeverType;
10+
use PHPStan\Type\NullType;
11+
use PHPStan\Type\Type;
12+
use PHPStan\Type\TypeCombinator;
13+
use PHPStan\Type\UnionType;
14+
use Salient\Core\Utility\Arr;
15+
use Salient\Core\Utility\Get;
16+
17+
class MethodReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension
18+
{
19+
public function getClass(): string
20+
{
21+
return Get::class;
22+
}
23+
24+
public function isStaticMethodSupported(
25+
MethodReflection $methodReflection
26+
): bool {
27+
return $methodReflection->getName() === 'coalesce';
28+
}
29+
30+
public function getTypeFromStaticMethodCall(
31+
MethodReflection $methodReflection,
32+
StaticCall $methodCall,
33+
Scope $scope
34+
): ?Type {
35+
$null = new NullType();
36+
37+
$args = $methodCall->getArgs();
38+
39+
if ($args === []) {
40+
return $null;
41+
}
42+
43+
$types = [];
44+
$last = null;
45+
foreach ($args as $arg) {
46+
$type = $scope->getType($arg->value);
47+
48+
// Unpack variadic arguments
49+
if ($arg->unpack) {
50+
$type = $type->getIterableValueType();
51+
52+
if ($type instanceof NeverType) {
53+
continue;
54+
}
55+
56+
if ($type instanceof UnionType) {
57+
$type = $type->getTypes();
58+
}
59+
}
60+
61+
foreach (Arr::wrap($type) as $type) {
62+
$last = $type;
63+
$isNull = $null->isSuperTypeOf($type);
64+
if ($isNull->yes()) {
65+
continue;
66+
}
67+
if ($isNull->no()) {
68+
break 2;
69+
}
70+
$types[] = TypeCombinator::removeNull($type);
71+
}
72+
}
73+
74+
if ($last) {
75+
$types[] = $last;
76+
}
77+
78+
if ($types === []) {
79+
return $null;
80+
}
81+
82+
return TypeCombinator::union(...$types);
83+
}
84+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\PHPStan\Core\Utility\Str;
4+
5+
use PhpParser\Node\Expr\StaticCall;
6+
use PHPStan\Analyser\Scope;
7+
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\Constant\ConstantStringType;
9+
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
10+
use PHPStan\Type\NeverType;
11+
use PHPStan\Type\NullType;
12+
use PHPStan\Type\Type;
13+
use PHPStan\Type\TypeCombinator;
14+
use PHPStan\Type\UnionType;
15+
use Salient\Core\Utility\Arr;
16+
use Salient\Core\Utility\Str;
17+
18+
class MethodReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension
19+
{
20+
public function getClass(): string
21+
{
22+
return Str::class;
23+
}
24+
25+
public function isStaticMethodSupported(
26+
MethodReflection $methodReflection
27+
): bool {
28+
return $methodReflection->getName() === 'coalesce';
29+
}
30+
31+
public function getTypeFromStaticMethodCall(
32+
MethodReflection $methodReflection,
33+
StaticCall $methodCall,
34+
Scope $scope
35+
): ?Type {
36+
$null = new NullType();
37+
38+
$args = $methodCall->getArgs();
39+
40+
if ($args === []) {
41+
return $null;
42+
}
43+
44+
$empty = new UnionType([new ConstantStringType(''), $null]);
45+
46+
$types = [];
47+
$last = null;
48+
foreach ($args as $arg) {
49+
$type = $scope->getType($arg->value);
50+
51+
// Unpack variadic arguments
52+
if ($arg->unpack) {
53+
$type = $type->getIterableValueType();
54+
55+
if ($type instanceof NeverType) {
56+
continue;
57+
}
58+
59+
if ($type instanceof UnionType) {
60+
$type = $type->getTypes();
61+
}
62+
}
63+
64+
foreach (Arr::wrap($type) as $type) {
65+
$last = $type;
66+
$isEmpty = $empty->isSuperTypeOf($type);
67+
if ($isEmpty->yes()) {
68+
continue;
69+
}
70+
if ($isEmpty->no()) {
71+
break 2;
72+
}
73+
$types[] = TypeCombinator::remove($type, $empty);
74+
}
75+
}
76+
77+
if ($last) {
78+
$types[] = $last;
79+
}
80+
81+
if ($types === []) {
82+
return $null;
83+
}
84+
85+
return TypeCombinator::union(...$types);
86+
}
87+
}

src/Sli/Command/Generate/Concept/GenerateCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ protected function resolveTemplates(string $type, array $templates, ?PhpDocTempl
415415
*/
416416
protected function getPhpDocTypeAlias($type, array $templates, string $namespace, ?string $filename = null, array &$inputClassTemplates = []): string
417417
{
418-
/** @var string */
419418
$subject = $type instanceof PhpDocTag
420419
? Str::coalesce($type->Type, '')
421420
: $type;

0 commit comments

Comments
 (0)