• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bitExpert / phpstan-magento / 13551485180

26 Feb 2025 07:06PM UTC coverage: 87.989% (-0.3%) from 88.269%
13551485180

push

github

web-flow
Merge pull request #337 from shochdoerfer/fix/ci_pipeline

Fix CI pipeline issues

630 of 716 relevant lines covered (87.99%)

1.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/src/bitExpert/PHPStan/Magento/Rules/AbstractModelRetrieveCollectionViaFactoryRule.php
1
<?php
2

3
/*
4
 * This file is part of the phpstan-magento package.
5
 *
6
 * (c) bitExpert AG
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
declare(strict_types=1);
12

13
namespace bitExpert\PHPStan\Magento\Rules;
14

15
use PhpParser\Node;
16
use PhpParser\Node\Expr\MethodCall;
17
use PHPStan\Analyser\Scope;
18
use PHPStan\Rules\Rule;
19
use PHPStan\Rules\RuleError;
20
use PHPStan\Rules\RuleErrorBuilder;
21
use PHPStan\Type\ObjectType;
22
use PHPStan\Type\VerbosityLevel;
23

24
/**
25
 * Since 101.0.0 because collections should be used directly via factory
26
 *
27
 * @implements Rule<MethodCall>
28
 */
29
class AbstractModelRetrieveCollectionViaFactoryRule implements Rule
30
{
31
    /**
32
     * @phpstan-return class-string<MethodCall>
33
     * @return string
34
     */
35
    public function getNodeType(): string
36
    {
37
        return MethodCall::class;
2✔
38
    }
39

40
    public function processNode(Node $node, Scope $scope): array
41
    {
42
        if (!$node->name instanceof Node\Identifier) {
3✔
43
            return [];
1✔
44
        }
45

46
        if ($node->name->name !== 'getCollection') {
2✔
47
            return [];
1✔
48
        }
49

50
        $type = $scope->getType($node->var);
1✔
51
        $isAbstractModelType = (new ObjectType('Magento\Framework\Model\AbstractModel'))->isSuperTypeOf($type);
1✔
52
        if (!$isAbstractModelType->yes()) {
1✔
53
            return [];
×
54
        }
55

56
        return [
1✔
57
            RuleErrorBuilder::message(
1✔
58
                sprintf(
1✔
59
                    'Collections should be used directly via factory, not via %s::%s() method',
1✔
60
                    $type->describe(VerbosityLevel::typeOnly()),
1✔
61
                    $node->name->name
1✔
62
                )
1✔
63
            )
1✔
64
            ->identifier('bitExpertMagento.abstractModelRetrieveCollectionViaFactory')
1✔
65
            ->build()
1✔
66
        ];
1✔
67
    }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc