Skip to content

Commit 346484d

Browse files
committed
Update CS
1 parent 28cb4bb commit 346484d

File tree

78 files changed

+453
-295
lines changed

Some content is hidden

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

78 files changed

+453
-295
lines changed

build-cs/composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"require-dev": {
3-
"consistence-community/coding-standard": "^3.10",
3+
"consistence-community/coding-standard": "^3.11",
44
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
5-
"slevomat/coding-standard": "^6.4"
5+
"slevomat/coding-standard": "^7.0",
6+
"squizlabs/php_codesniffer": "^3.6.2"
67
},
78
"config": {
89
"allow-plugins": {

phpcs.xml

+68-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0"?>
22
<ruleset name="PHPStan Doctrine">
3+
<config name="php_version" value="70100"/>
34
<arg name="colors"/>
45
<arg name="extensions" value="php"/>
56
<arg name="encoding" value="utf-8"/>
@@ -8,64 +9,104 @@
89
<arg value="sp"/>
910
<file>src</file>
1011
<file>tests</file>
12+
1113
<rule ref="build-cs/vendor/consistence-community/coding-standard/Consistence/ruleset.xml">
12-
<exclude name="Squiz.Functions.GlobalFunction.Found"/>
13-
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
14+
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.InvalidFormat"/>
15+
<exclude name="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable"/>
1416
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
1517
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
16-
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
1718
<exclude name="Consistence.Exceptions.ExceptionDeclaration"/>
18-
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
19+
<exclude name="Squiz.Commenting.FunctionComment"/>
20+
<exclude name="Squiz.PHP.Heredoc.NotAllowed"/>
21+
<exclude name="Squiz.WhiteSpace.FunctionSpacing.Before"/>
1922
</rule>
2023
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
2124
<properties>
2225
<property name="caseSensitive" value="false"/>
26+
<property name="psr12Compatible" value="true"/>
2327
</properties>
2428
</rule>
2529
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
2630
<properties>
27-
<property name="newlinesCountBetweenOpenTagAndDeclare" value="0"/>
31+
<property name="declareOnFirstLine" value="true"/>
2832
</properties>
2933
</rule>
3034
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
31-
<properties>
32-
<property name="usefulAnnotations" type="array" value="
33-
@dataProvider,
34-
@requires
35-
"/>
36-
<property name="enableObjectTypeHint" value="false"/>
37-
</properties>
38-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
39-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
40-
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint"/>
35+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
4136
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
4237
</rule>
38+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation">
39+
<severity>10</severity>
40+
</rule>
4341
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
44-
<properties>
45-
<property name="enableNativeTypeHint" value="false"/>
46-
</properties>
4742
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
4843
</rule>
44+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation">
45+
<severity>10</severity>
46+
</rule>
4947
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
50-
<properties>
51-
<property name="enableObjectTypeHint" value="false"/>
52-
</properties>
5348
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
5449
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint"/>
50+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
51+
</rule>
52+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation">
53+
<severity>10</severity>
5554
</rule>
55+
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure.UnusedInheritedVariable"/>
56+
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException"/>
57+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable"/>
5658
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
57-
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
58-
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
59+
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit">
60+
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit.UselessElseIf"/>
61+
</rule>
5962
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
6063
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
61-
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowShortTernaryOperator"/>-->
62-
<!-- <rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/> -->
63-
<!-- <rule ref="SlevomatCodingStandard.PHP.ShortList"/> -->
6464
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
6565
<properties>
66-
<property name="rootNamespaces" type="array" value="src=>PHPStan,tests=>PHPStan"/>
66+
<property name="rootNamespaces" type="array">
67+
<element key="src" value="PHPStan"/>
68+
<element key="tests" value="PHPStan"/>
69+
</property>
70+
71+
</properties>
72+
</rule>
73+
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
74+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
75+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
76+
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
77+
<rule ref="SlevomatCodingStandard.TypeHints.NullTypeHintOnLastPosition"/>
78+
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
79+
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing"/>
80+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable"/>
81+
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
82+
<!--<rule ref="SlevomatCodingStandard.Functions.UnusedParameter"/>-->
83+
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
84+
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
85+
<properties>
86+
<property name="searchAnnotations" value="true"/>
87+
<property name="namespacesRequiredToUse" value=""/>
88+
<property name="allowPartialUses" value="true"/>
89+
<property name="allowFallbackGlobalFunctions" value="false"/>
90+
<property name="allowFallbackGlobalConstants" value="false"/>
91+
<property name="allowFullyQualifiedExceptions" value="false"/>
92+
<property name="allowFullyQualifiedNameForCollidingClasses" value="true"/>
93+
<property name="allowFullyQualifiedNameForCollidingFunctions" value="true"/>
94+
<property name="allowFullyQualifiedNameForCollidingConstants" value="true"/>
95+
</properties>
96+
</rule>
97+
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
98+
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing"/>
99+
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
100+
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
101+
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
102+
<properties>
103+
<property name="spacing" value="1" />
104+
<property name="spacingBeforeFirst" value="1"/>
105+
<property name="spacingAfterLast" value="1"/>
67106
</properties>
68107
</rule>
108+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/>
109+
<rule ref="Consistence.NamingConventions.ValidVariableName.NotCamelCaps"/>
69110
<exclude-pattern>tests/tmp</exclude-pattern>
70111
<exclude-pattern>tests/*/data</exclude-pattern>
71112
<exclude-pattern>tests/*/data-attributes</exclude-pattern>

phpstan-baseline-dbal-3.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ parameters:
22
ignoreErrors:
33
-
44
message: "#^Class Doctrine\\\\DBAL\\\\Platforms\\\\MySQLPlatform referenced with incorrect case\\: Doctrine\\\\DBAL\\\\Platforms\\\\MySqlPlatform\\.$#"
5-
count: 2
5+
count: 3
66
path: src/Doctrine/Mapping/ClassMetadataFactory.php
77

88
-

src/Doctrine/Mapping/ClassMetadataFactory.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44

55
use Doctrine\Common\Annotations\AnnotationReader;
66
use Doctrine\Common\EventManager;
7+
use Doctrine\DBAL\Platforms\MySqlPlatform;
78
use Doctrine\ORM\Mapping\ClassMetadata;
89
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
910
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
11+
use ReflectionClass;
1012
use function class_exists;
13+
use function count;
14+
use const PHP_VERSION_ID;
1115

1216
class ClassMetadataFactory extends \Doctrine\ORM\Mapping\ClassMetadataFactory
1317
{
1418

1519
protected function initialize(): void
1620
{
17-
$parentReflection = new \ReflectionClass(parent::class);
21+
$parentReflection = new ReflectionClass(parent::class);
1822
$driverProperty = $parentReflection->getProperty('driver');
1923
$driverProperty->setAccessible(true);
2024

@@ -36,15 +40,19 @@ protected function initialize(): void
3640
$targetPlatformProperty = $parentReflection->getProperty('targetPlatform');
3741
$targetPlatformProperty->setAccessible(true);
3842

39-
if (class_exists(\Doctrine\DBAL\Platforms\MySqlPlatform::class)) {
40-
$platform = new \Doctrine\DBAL\Platforms\MySqlPlatform();
43+
if (class_exists(MySqlPlatform::class)) {
44+
$platform = new MySqlPlatform();
4145
} else {
4246
$platform = new \Doctrine\DBAL\Platforms\MySQLPlatform();
4347
}
4448

4549
$targetPlatformProperty->setValue($this, $platform);
4650
}
4751

52+
/**
53+
* @param string $className
54+
* @return ClassMetadata
55+
*/
4856
protected function newClassMetadataInstance($className)
4957
{
5058
return new ClassMetadata($className);

src/Reflection/Doctrine/DoctrineSelectableClassReflectionExtension.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,30 @@
22

33
namespace PHPStan\Reflection\Doctrine;
44

5-
class DoctrineSelectableClassReflectionExtension implements \PHPStan\Reflection\MethodsClassReflectionExtension, \PHPStan\Reflection\BrokerAwareExtension
5+
use PHPStan\Broker\Broker;
6+
use PHPStan\Reflection\BrokerAwareExtension;
7+
use PHPStan\Reflection\ClassReflection;
8+
use PHPStan\Reflection\MethodReflection;
9+
use PHPStan\Reflection\MethodsClassReflectionExtension;
10+
11+
class DoctrineSelectableClassReflectionExtension implements MethodsClassReflectionExtension, BrokerAwareExtension
612
{
713

8-
/** @var \PHPStan\Broker\Broker */
14+
/** @var Broker */
915
private $broker;
1016

11-
public function setBroker(\PHPStan\Broker\Broker $broker): void
17+
public function setBroker(Broker $broker): void
1218
{
1319
$this->broker = $broker;
1420
}
1521

16-
public function hasMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): bool
22+
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
1723
{
1824
return $classReflection->getName() === 'Doctrine\Common\Collections\Collection'
1925
&& $methodName === 'matching';
2026
}
2127

22-
public function getMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): \PHPStan\Reflection\MethodReflection
28+
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
2329
{
2430
$selectableReflection = $this->broker->getClass('Doctrine\Common\Collections\Selectable');
2531
return $selectableReflection->getNativeMethod($methodName);

src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php

+20-10
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@
33
namespace PHPStan\Reflection\Doctrine;
44

55
use Doctrine\Persistence\ObjectRepository;
6+
use PHPStan\Reflection\ClassReflection;
7+
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Reflection\MethodsClassReflectionExtension;
9+
use PHPStan\ShouldNotHappenException;
610
use PHPStan\Type\ArrayType;
711
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
812
use PHPStan\Type\IntegerType;
913
use PHPStan\Type\NullType;
1014
use PHPStan\Type\TypeCombinator;
1115
use PHPStan\Type\TypeWithClassName;
12-
13-
class EntityRepositoryClassReflectionExtension implements \PHPStan\Reflection\MethodsClassReflectionExtension
16+
use function lcfirst;
17+
use function str_replace;
18+
use function strlen;
19+
use function strpos;
20+
use function substr;
21+
use function ucwords;
22+
23+
class EntityRepositoryClassReflectionExtension implements MethodsClassReflectionExtension
1424
{
1525

16-
/** @var \PHPStan\Type\Doctrine\ObjectMetadataResolver */
26+
/** @var ObjectMetadataResolver */
1727
private $objectMetadataResolver;
1828

1929
public function __construct(ObjectMetadataResolver $objectMetadataResolver)
2030
{
2131
$this->objectMetadataResolver = $objectMetadataResolver;
2232
}
2333

24-
public function hasMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): bool
34+
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
2535
{
2636
if (
2737
strpos($methodName, 'findBy') === 0
@@ -44,7 +54,7 @@ public function hasMethod(\PHPStan\Reflection\ClassReflection $classReflection,
4454

4555
$repositoryAncesor = $classReflection->getAncestorWithClassName(ObjectRepository::class);
4656
if ($repositoryAncesor === null) {
47-
$repositoryAncesor = $classReflection->getAncestorWithClassName(\Doctrine\Persistence\ObjectRepository::class);
57+
$repositoryAncesor = $classReflection->getAncestorWithClassName(ObjectRepository::class);
4858
if ($repositoryAncesor === null) {
4959
return false;
5060
}
@@ -79,20 +89,20 @@ private function classify(string $word): string
7989
return lcfirst(str_replace([' ', '_', '-'], '', ucwords($word, ' _-')));
8090
}
8191

82-
public function getMethod(\PHPStan\Reflection\ClassReflection $classReflection, string $methodName): \PHPStan\Reflection\MethodReflection
92+
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
8393
{
8494
$repositoryAncesor = $classReflection->getAncestorWithClassName(ObjectRepository::class);
8595
if ($repositoryAncesor === null) {
86-
$repositoryAncesor = $classReflection->getAncestorWithClassName(\Doctrine\Persistence\ObjectRepository::class);
96+
$repositoryAncesor = $classReflection->getAncestorWithClassName(ObjectRepository::class);
8797
if ($repositoryAncesor === null) {
88-
throw new \PHPStan\ShouldNotHappenException();
98+
throw new ShouldNotHappenException();
8999
}
90100
}
91101

92102
$templateTypeMap = $repositoryAncesor->getActiveTemplateTypeMap();
93103
$entityClassType = $templateTypeMap->getType('TEntityClass');
94104
if ($entityClassType === null) {
95-
throw new \PHPStan\ShouldNotHappenException();
105+
throw new ShouldNotHappenException();
96106
}
97107

98108
if (
@@ -108,7 +118,7 @@ public function getMethod(\PHPStan\Reflection\ClassReflection $classReflection,
108118
) {
109119
$returnType = new IntegerType();
110120
} else {
111-
throw new \PHPStan\ShouldNotHappenException();
121+
throw new ShouldNotHappenException();
112122
}
113123

114124
return new MagicRepositoryMethodReflection($repositoryAncesor, $methodName, $returnType);

0 commit comments

Comments
 (0)