Skip to content

Commit 49b641d

Browse files
authored
Merge pull request #706 from driehle/feature/static-analysis
Improved types and make static analysis more strict
2 parents f4ff40e + 448a568 commit 49b641d

14 files changed

+61
-65
lines changed

phpstan.neon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
parameters:
2-
level: 5
2+
level: 6
33
paths:
44
- src
55
- tests
6+
checkGenericClassInNonGenericObjectType: false
67
treatPhpDocTypesAsCertain: false
78
ignoreErrors:
9+
-
10+
message: '#Method .*EntityBasedFormBuilder::createForm\(\) .* iterable type .*FormInterface#'
11+
path: src/Form/Annotation/EntityBasedFormBuilder.php
812
-
913
message: '#Offset class-string<object> on array\{\} in isset\(\) does not exist#'
1014
path: src/Yuml/MetadataGrapher.php

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="5"
3+
errorLevel="4"
44
phpVersion="8.0"
55
resolveFromConfigFile="true"
66
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

src/Collector/MappingCollector.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,20 @@ class MappingCollector implements CollectorInterface, AutoHideInterface
3232
public function __construct(ClassMetadataFactory $classMetadataFactory, string $name)
3333
{
3434
$this->classMetadataFactory = $classMetadataFactory;
35-
$this->name = (string) $name;
35+
$this->name = $name;
3636
}
3737

38-
/**
39-
* {@inheritDoc}
40-
*/
41-
public function getName()
38+
public function getName(): string
4239
{
4340
return $this->name;
4441
}
4542

46-
/**
47-
* {@inheritDoc}
48-
*/
49-
public function getPriority()
43+
public function getPriority(): int
5044
{
5145
return self::PRIORITY;
5246
}
5347

54-
/**
55-
* {@inheritDoc}
56-
*/
57-
public function collect(MvcEvent $mvcEvent)
48+
public function collect(MvcEvent $mvcEvent): void
5849
{
5950
if (! $this->classMetadataFactory) {
6051
return;
@@ -71,10 +62,7 @@ public function collect(MvcEvent $mvcEvent)
7162
ksort($this->classes);
7263
}
7364

74-
/**
75-
* {@inheritDoc}
76-
*/
77-
public function canHide()
65+
public function canHide(): bool
7866
{
7967
return empty($this->classes);
8068
}

src/Collector/SQLLoggerCollector.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,24 @@ class SQLLoggerCollector implements CollectorInterface, AutoHideInterface
2828
public function __construct(DebugStack $sqlLogger, string $name)
2929
{
3030
$this->sqlLogger = $sqlLogger;
31-
$this->name = (string) $name;
31+
$this->name = $name;
3232
}
3333

34-
/**
35-
* {@inheritDoc}
36-
*/
37-
public function getName()
34+
public function getName(): string
3835
{
3936
return $this->name;
4037
}
4138

42-
/**
43-
* {@inheritDoc}
44-
*/
45-
public function getPriority()
39+
public function getPriority(): int
4640
{
4741
return self::PRIORITY;
4842
}
4943

50-
/**
51-
* {@inheritDoc}
52-
*/
53-
public function collect(MvcEvent $mvcEvent)
44+
public function collect(MvcEvent $mvcEvent): void
5445
{
5546
}
5647

57-
/**
58-
* {@inheritDoc}
59-
*/
60-
public function canHide()
48+
public function canHide(): bool
6149
{
6250
return empty($this->sqlLogger->queries);
6351
}

src/Form/Annotation/EntityBasedFormBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function getFormSpecification($entity): ArrayObject
136136
/**
137137
* Create a form from an object.
138138
*
139-
* @param class-string|object $entity
139+
* @param class-string|object $entity
140140
*/
141141
public function createForm($entity): FormInterface
142142
{

src/Module.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Laminas\ModuleManager\Feature\ConfigProviderInterface;
1010
use Laminas\ModuleManager\Feature\ControllerProviderInterface;
1111
use Laminas\ModuleManager\Feature\DependencyIndicatorInterface;
12+
use Laminas\ModuleManager\Feature\InitProviderInterface;
1213
use Laminas\ModuleManager\ModuleManagerInterface;
1314

1415
use function class_exists;
@@ -19,12 +20,10 @@
1920
class Module implements
2021
ControllerProviderInterface,
2122
ConfigProviderInterface,
22-
DependencyIndicatorInterface
23+
DependencyIndicatorInterface,
24+
InitProviderInterface
2325
{
24-
/**
25-
* {@inheritDoc}
26-
*/
27-
public function init(ModuleManagerInterface $manager)
26+
public function init(ModuleManagerInterface $manager): void
2827
{
2928
// Initialize the console
3029
$manager
@@ -60,24 +59,30 @@ static function ($event): void {
6059

6160
/**
6261
* {@inheritDoc}
62+
*
63+
* @return array<array-key,mixed>
6364
*/
64-
public function getConfig()
65+
public function getConfig(): array
6566
{
6667
return include __DIR__ . '/../config/module.config.php';
6768
}
6869

6970
/**
7071
* {@inheritDoc}
72+
*
73+
* @return array<array-key,mixed>
7174
*/
72-
public function getControllerConfig()
75+
public function getControllerConfig(): array
7376
{
7477
return include __DIR__ . '/../config/controllers.config.php';
7578
}
7679

7780
/**
7881
* {@inheritDoc}
82+
*
83+
* @return array<string>
7984
*/
80-
public function getModuleDependencies()
85+
public function getModuleDependencies(): array
8186
{
8287
return ['DoctrineModule'];
8388
}

src/Options/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public function getRepositoryFactory()
537537
*/
538538
public function setClassMetadataFactoryName(string $factoryName): self
539539
{
540-
$this->classMetadataFactoryName = (string) $factoryName;
540+
$this->classMetadataFactoryName = $factoryName;
541541

542542
return $this;
543543
}
@@ -612,7 +612,7 @@ public function getFilterSchemaAssetsExpression(): ?string
612612
*/
613613
public function setDefaultRepositoryClassName(string $className): self
614614
{
615-
$this->defaultRepositoryClassName = (string) $className;
615+
$this->defaultRepositoryClassName = $className;
616616

617617
return $this;
618618
}

src/Options/DBALConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function getParams(): array
105105
*/
106106
public function setDoctrineTypeMappings(array $doctrineTypeMappings): DBALConnection
107107
{
108-
$this->doctrineTypeMappings = (array) $doctrineTypeMappings;
108+
$this->doctrineTypeMappings = $doctrineTypeMappings;
109109

110110
return $this;
111111
}

src/Options/EntityManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getConnection(): string
5656

5757
public function setEntityResolver(string $entityResolver): self
5858
{
59-
$this->entityResolver = (string) $entityResolver;
59+
$this->entityResolver = $entityResolver;
6060

6161
return $this;
6262
}

src/Options/SQLLoggerCollectorOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ public function getName(): string
3535

3636
public function setConfiguration(?string $configuration): void
3737
{
38-
$this->configuration = $configuration ? (string) $configuration : null;
38+
$this->configuration = $configuration ?: null;
3939
}
4040

4141
/**
4242
* Configuration service name (where to set the logger)
4343
*/
4444
public function getConfiguration(): string
4545
{
46-
return $this->configuration ? $this->configuration : 'doctrine.configuration.orm_default';
46+
return $this->configuration ?: 'doctrine.configuration.orm_default';
4747
}
4848

4949
public function setSqlLogger(?string $sqlLogger): void
5050
{
51-
$this->sqlLogger = $sqlLogger ? (string) $sqlLogger : null;
51+
$this->sqlLogger = $sqlLogger ?: null;
5252
}
5353

5454
/**

0 commit comments

Comments
 (0)