nextras / orm-phpstan Goto Github PK
View Code? Open in Web Editor NEWPHPStan extension for Nextras Orm
Home Page: https://nextras.org/orm
License: MIT License
PHPStan extension for Nextras Orm
Home Page: https://nextras.org/orm
License: MIT License
persist, persistAndFlush and other methods returns specific passed entity, not IEntity
Are you going to add support for new version of phpstan?
PHPStan 0.12.40
Nextras\Orm 4.0-RC1
Nextras\Orm-PHPStan dev-master
This makes PHPStan with active nextras/orm-phpstan extension to freeze when analysing the file.
<?php declare(strict_types=1);
namespace App\Model\System;
use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Mapper\Mapper;
final class LogMapper extends Mapper
{
public function findAllWithTranslatedIps(): ICollection
{
return $this->toCollection(
$this->builder()->addSelect('inet6_ntoa([ip]) as [ip]')
);
}
}
The issue persists even with just $this->builder()
suggesting error isn't in the custom select part.
Hello everyone ๐
I announced today that PHPStan 1.0 is going to be released on November 1st 2021.
I'm approaching you as one of the most popular PHPStan extensions. I'd love if you could prepare your code for PHPStan 1.0 in advance so that it's ready to release on the same day.
Here's a brief guide how to approach the upgrade:
"phpstan/phpstan": "^1.0"
, add "minimum-stability": "dev"
and "prefer-stable": true
if necessary.Thank you!
Here are the BC breaks. The list is huge but most of those have very little impact.
There are new rules around using PHPStan internals in regard to backward compatibility promise: https://phpstan.org/developing-extensions/backward-compatibility-promise
It's possible that not everything you use is covered by it - so I'm here to help you to transition to correct usage, or add some @api
annotations in PHPStan itself so that more is covered by the promise. Let me know!
max
is now level 9. Feel free to update max
to 8
if your code isn't ready.numeric-string
(it was previously described as string&numeric
), and also array shapes.baselineNeon
error formatter, use --generate-baseline
CLI option instead (phpstan/phpstan-src@492cfbc)polluteCatchScopeWithTryAssignments
config parameter (phpstan/phpstan-src@8933c7e)autoload_files
parameter - use Discovering Symbols instead (phpstan/phpstan-src@7a21246)autoload_directories
parameter - use Discovering Symbols instead (phpstan/phpstan-src@f67b48a)bootstrap
parameter - use bootstrapFiles
instead (phpstan/phpstan-src@1baa294)implicitThrows
configuration parameter to exceptions.implicitThrows
(phpstan/phpstan-src@96b7c48)--paths-file
CLI option (phpstan/phpstan-src@5670cf2)dump-deps
command (phpstan/phpstan-src@9c7017c)excludes_analyse
option, use excludePaths
instead (phpstan/phpstan-src@d25c5e5)The following are interesting only if you create a custom ruleset in your configuration file:
DeadCatchRule
, replaced by CatchWithUnthrownExceptionRule
(phpstan/phpstan-src@4dba60b)VariableCertaintyInIssetRule
, replaced by IssetRule
(phpstan/phpstan-src@2e858de)MissingClosureNativeReturnTypehintRule
, no longer needed thanks to type inference (phpstan/phpstan-src@1c34d8d)CompoundTypeHelper
(phpstan/phpstan-src@145c4e3)CommentHelper
(phpstan/phpstan-src@ebad6f6)DependencyDumper
(phpstan/phpstan-src@9c7017c)PHPStan\Reflection\Generic\ResolvedFunctionVariant
, replaced by PHPStan\Reflection\ResolvedFunctionVariant
(phpstan/phpstan-src@1cc6c81)ClassReflection::getNativeMethods()
, use getNativeReflection()
instead (phpstan/phpstan-src@d2c1446)PhpPropertyReflection::hasPhpDoc()
, replaced by hasPhpDocType()
(phpstan/phpstan-src@bedd5be)NodeDependencies
no longer iterable (phpstan/phpstan-src@f76875a)TestCase
to PHPStanTestCase
(#634), thanks @frankdejonge!StaticType
and ThisType
- require ClassReflection
in constructor (phpstan/phpstan-src@7aabc84)PHPStanTestCase
- extensions can no longer be provided by overriding methods from PHPStanTestCase
. Use getAdditionalConfigFiles()
instead. (phpstan/phpstan-src@65efd93, phpstan/phpstan-src@239291a)|false
to |null
(phpstan/phpstan-src@629ccf6)BrokerAwareExtension
(phpstan/phpstan-src@db2f7fb)PHPStanTestCase::createBroker()
. Use createReflectionProvider()
instead. (phpstan/phpstan-src@1e5cf58)PHPStan\Broker\Broker
. Use PHPStan\Reflection\ReflectionProvider
instead. (phpstan/phpstan-src@c775594)PHPStan\Broker\Broker::getInstance()
. Use PHPStan\Reflection\ReflectionProviderStaticAccessor
instead. (phpstan/phpstan-src@4e7d60d)Parent here seems not to correctly work as $this->.
class AffiliateCodeRepository extends Repository
{
/**
* @return ICollection<AffiliateCode>
*/
public function findActive(): ICollection
{
return parent::findBy(['active' => true]);
}
}
Having similar definition
/**
* @property int $id {primary}
* @property Author $author {m:1 Author::$books}
*/
class Book extends Nextras\Orm\Entity\Entity
{}
and calling $book->author = 1;
generates
Property Book::$author (Author) does not accept int.
although the Author entity is correctly auto-loaded.
After upgrading to latest PHPStan (currently 0.12.29), the extension is broken. I suspect it's because of the reflection change which happened in PHPStan (https://phpstan.org/blog/zero-config-analysis-with-static-reflection). If extension is removed, PHPStan proceeds with analysis and (correctly) reports errors based on not knowing context of Nextras\Orm.
Example of Stack trace thrown by --debug
switch.
Stack trace:
#0 C:\WebServer\WebRoot\project\vendor\nextras\orm-phpstan\src\Types\RepositoryReturnTypeExtension.php(75): ReflectionClass->__construct('App\\Model\\Files...')
#1 phar://C:/WebServer/WebRoot/project/vendor/phpstan/phpstan/phpstan/src/Analyser/MutatingScope.php(2505): Nextras\OrmPhpStan\Types\RepositoryReturnTypeExtension->getTypeFromMethodCall(Object(PHPStan\Reflection\ObjectTypeMethodReflection), Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope))
#2 phar://C:/WebServer/WebRoot/project/vendor/phpstan/phpstan/phpstan/src/Analyser/MutatingScope.php(1176): PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\ObjectType), Object(PHPStan\Type\ObjectType), 'persistAndFlush', Object(PhpParser\Node\Expr\MethodCall))
#3 phar://C:/WebServer/WebR in C:\WebServer\WebRoot\project\vendor\nextras\orm-phpstan\src\Types\RepositoryReturnTypeExtension.php on line 75
Fatal error: Uncaught ReflectionException: Class App\Model\Files\FileRepository does not exist in C:\WebServer\WebRoot\project\vendor\nextras\orm-phpstan\src\Types\RepositoryReturnTypeExtension.php:75
Stack trace:
#0 C:\WebServer\WebRoot\project\vendor\nextras\orm-phpstan\src\Types\RepositoryReturnTypeExtension.php(75): ReflectionClass->__construct('App\\Model\\Files...')
#1 phar://C:/WebServer/WebRoot/project/vendor/phpstan/phpstan/phpstan/src/Analyser/MutatingScope.php(2505): Nextras\OrmPhpStan\Types\RepositoryReturnTypeExtension->getTypeFromMethodCall(Object(PHPStan\Reflection\ObjectTypeMethodReflection), Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope))
#2 phar://C:/WebServer/WebRoot/project/vendor/phpstan/phpstan/phpstan/src/Analyser/MutatingScope.php(1176): PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\ObjectType), Object(PHPStan\Type\ObjectType), 'persistAndFlush', Object(PhpParser\Node\Expr\MethodCall))
#3 phar://C:/WebServer/WebR in C:\WebServer\WebRoot\project\vendor\nextras\orm-phpstan\src\Types\RepositoryReturnTypeExtension.php on line 75
nextras/orm 4.0, nextras/orm-phpstan 0.6.1, phpstan/phpstan 0.12.30
Fatal error: Uncaught Error: Call to undefined method PHPStan\Type\UnionType::getClassName() in /var/docker/vendor/nextras/orm-phpstan/src/Types/RepositoryReturnTypeExtension.php:76
Stack trace:
#0 phar:///var/docker/vendor/phpstan/phpstan/phpstan/src/Analyser/MutatingScope.php(2527): Nextras\OrmPhpStan\Types\RepositoryReturnTypeExtension->getTypeFromMethodCall(Object(PHPStan\Reflection\ObjectTypeMethodReflection), Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope))
#1 phar:///var/docker/vendor/phpstan/phpstan/phpstan/src/Analyser/MutatingScope.php(1196): PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\ObjectType), Object(PHPStan\Type\ObjectType), 'findAll', Object(PhpParser\Node\Expr\MethodCall))
#2 phar:///var/docker/vendor/phpstan/phpstan/phpstan/src/Type/TypeTraverser.php(47): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}(Object(PHPStan\Type\ObjectType), Array)
#3 phar:///var/docker/vendor/phpstan/phpstan/phpstan/src/Type/UnionType.php(415): PHPStan\Typ in /var/docker/vendor/nextras/orm-phpstan/src/Types/RepositoryReturnTypeExtension.php on line 76
I don't get it why this error even occurs. This should not ever happen, because it's protected by assert
right?
https://github.com/nextras/orm-phpstan/blob/master/src/Types/RepositoryReturnTypeExtension.php#L74
But for some WEIRD reason, assert passes.
Code that probably caused this error:
/** @var ChannelPredefinedDataAdformFormatRepository|ChannelPredefinedDataSmartRepository|null $repository */
$repository = null;
Child process error (exit code 255): PHP Fatal error: Class Nextras\Orm\Mapper\Dbal\DbalCollection contains 2 abstract methods
and must therefore be declared abstract or implement the remaining methods (Nextras\Orm\Collection\ICollection::getByChecked,
Nextras\Orm\Collection\ICollection::getByIdChecked) in
vendor/nextras/orm/src/Mapper/Dbal/DbalCollection.php on line 23
Fatal error: Class Nextras\Orm\Mapper\Dbal\DbalCollection contains 2 abstract methods and must therefore be declared abstract or
implement the remaining methods (Nextras\Orm\Collection\ICollection::getByChecked,
Nextras\Orm\Collection\ICollection::getByIdChecked) in
vendor/nextras/orm/src/Mapper/Dbal/DbalCollection.php on line 23
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.