Skip to content

Commit

Permalink
Raise Psalm to level 3
Browse files Browse the repository at this point in the history
This includes:
  - adding assertions to avoid nullable values
  - Override phpdoc to be more specific

Apart from ignore some issues.
  • Loading branch information
franmomu committed Apr 21, 2021
1 parent 5bb4b3e commit a29f2bf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use function array_map;
use function array_reverse;
use function array_unshift;
use function assert;
use function explode;
use function sprintf;
use function str_replace;
Expand Down Expand Up @@ -498,6 +499,8 @@ private function getRealClass(string $class): string
$this->createDefaultProxyClassNameResolver();
}

assert($this->proxyClassNameResolver !== null);

return $this->proxyClassNameResolver->resolveClassName($class);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Persistence/Mapping/MappingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function fileMappingDriversRequireConfiguredDirectoryPath($path =
return new self(sprintf(
'File mapping drivers must have a valid directory path, ' .
'however the given path %s seems to be incorrect!',
$path
(string) $path
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public function getClassNamespace($class)
}

/**
* {@inheritDoc}
* @param string $class
* @psalm-param class-string $class
*
* @return ReflectionClass
*/
public function getClass($class)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace Doctrine\Persistence\Reflection;

use Closure;
use ReflectionProperty;

use function assert;

/**
* PHP Typed No Default Reflection Property - special override for typed properties without a default value.
*/
Expand Down Expand Up @@ -38,6 +41,9 @@ public function setValue($object, $value = null)
unset($this->$propertyName);
};
$unsetter = $unsetter->bindTo($object, $this->getDeclaringClass()->getName());

assert($unsetter instanceof Closure);

$unsetter();

return;
Expand Down
17 changes: 14 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
errorLevel="4"
resolveFromConfigFile="true"
errorLevel="3"
findUnusedPsalmSuppress="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down Expand Up @@ -39,5 +38,17 @@
<file name="tests/Doctrine/Tests/Persistence/Mapping/SymfonyFileLocatorTest.php"/>
</errorLevel>
</NullArgument>
<ArgumentTypeCoercion>
<errorLevel type="suppress">
<!-- On purpose to use a non existing class for tests -->
<file name="tests/Doctrine/Tests/Persistence/Mapping/RuntimeReflectionServiceTest.php"/>
</errorLevel>
</ArgumentTypeCoercion>
<MoreSpecificReturnType>
<errorLevel type="suppress">
<!-- FileDriver::loadMappingFile() in tests could have a more specific return, but is not needed -->
<file name="tests/Doctrine/Tests/Persistence/Mapping/FileDriverTest.php"/>
</errorLevel>
</MoreSpecificReturnType>
</issueHandlers>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(ObjectManager $wrapped)

class ObjectManagerDecoratorTest extends TestCase
{
/** @var MockObject|ObjectManager */
/** @var MockObject&ObjectManager */
private $wrapped;

/** @var NullObjectManagerDecorator */
Expand Down

0 comments on commit a29f2bf

Please sign in to comment.