Coder Social home page Coder Social logo

orm-phpstan's People

Contributors

adaamz avatar demmmmios avatar hrach avatar jtojnar avatar mabar avatar mrceperka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

orm-phpstan's Issues

Call to undefined method PHPStan\Type\UnionType::getClassName()

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.
image
image

Code that probably caused this error:

/** @var ChannelPredefinedDataAdformFormatRepository|ChannelPredefinedDataSmartRepository|null $repository */
$repository = null;

Broken with latest PHPStan

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

Mapper::toCollection() breaks 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.

parent in Repository

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]);
    }
}

phpstan cries with Nextras ORM 4

     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

Incompatible types: Expected property

Hello,

Incompatible types: Expected property of type '\App\Database\Entity\Project', '\Nextras\Orm\Entity\IEntity|null' provided

How to solve this phpstan msg? Static analyse give me this "error"

image

Thank you,

Prepare for PHPStan 1.0

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:

  1. Create a branch ๐ŸŒด
  2. Update your composer.json to "phpstan/phpstan": "^1.0", add "minimum-stability": "dev" and "prefer-stable": true if necessary.
  3. Update your code with the BC breaks below in mind. ๐Ÿ”ง
  4. Fix the code so that it passes PHPStan's analysis ๐Ÿค“
  5. Wait for PHPStan 1.0 release on November 1st, merge your branch and tag the next major version ๐Ÿ‘

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!

BC breaks for end-users

The following are interesting only if you create a custom ruleset in your configuration file:

BC breaks for extension developers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.