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

bitExpert / phpstan-magento / 14927363969

09 May 2025 10:54AM UTC coverage: 88.0%. Remained the same
14927363969

Pull #340

github

web-flow
Merge 21f87d541 into 942283892
Pull Request #340: fix: error where scopeConfig proxy would get $scopeType = default

0 of 1 new or added line in 1 file covered. (0.0%)

638 of 725 relevant lines covered (88.0%)

1.77 hits per line

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

92.0
/src/bitExpert/PHPStan/Magento/Rules/GetCollectionMockMethodNeedsCollectionSubclassRule.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 bitExpert\PHPStan\Magento\Type\TestFrameworkObjectManagerDynamicReturnTypeExtension;
16
use PhpParser\Node;
17
use PhpParser\Node\Expr\MethodCall;
18
use PHPStan\Analyser\Scope;
19
use PHPStan\Rules\Rule;
20
use PHPStan\Rules\RuleError;
21
use PHPStan\Rules\RuleErrorBuilder;
22
use PHPStan\Type\Constant\ConstantStringType;
23
use PHPStan\Type\ErrorType;
24
use PHPStan\Type\ObjectType;
25

26
/**
27
 * \Magento\Framework\TestFramework\Unit\Helper\ObjectManager::getCollectionMock() needs first parameter to extend
28
 * \Magento\Framework\Data\Collection
29
 *
30
 * @implements Rule<MethodCall>
31
 */
32
class GetCollectionMockMethodNeedsCollectionSubclassRule implements Rule
33
{
34
    /**
35
     * @return class-string<\PhpParser\Node\Expr\MethodCall>
36
     */
37
    public function getNodeType(): string
38
    {
39
        return MethodCall::class;
2✔
40
    }
41

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

48
        if ($node->name->name !== 'getCollectionMock') {
2✔
49
            return [];
1✔
50
        }
51

52
        $dynReturnTypeExt = new TestFrameworkObjectManagerDynamicReturnTypeExtension();
1✔
53

54
        $type = $scope->getType($node->var);
1✔
55
        $isAbstractModelType = (new ObjectType($dynReturnTypeExt->getClass()))->isSuperTypeOf($type);
1✔
56
        if (!$isAbstractModelType->yes()) {
1✔
57
            return [];
×
58
        }
59

60
        // the return type check is done in TestFrameworkObjectManagerDynamicReturnTypeExtension. When an ErrorType
61
        // is returned, it's an indication that the type check failed. That's why we only need to check for the
62
        // ErrorType here
63
        $returnType = $scope->getType($node);
1✔
64
        if (!$returnType->equals(new ErrorType())) {
1✔
65
            return [];
×
66
        }
67

68
        /** @var \PhpParser\Node\Arg[] $args */
69
        $args = $node->args;
1✔
70
        /** @var ConstantStringType $argType */
71
        $argType = $scope->getType($args[0]->value);
1✔
72

73
        return [
1✔
74
            RuleErrorBuilder::message(
1✔
75
                sprintf(
1✔
76
                    '%s does not extend \Magento\Framework\Data\Collection as required!',
1✔
77
                    $argType->getValue()
1✔
78
                )
1✔
79
            )
1✔
80
            ->identifier('bitExpertMagento.getCollectionMockMethodNeedsCollectionSubclass')
1✔
81
            ->build()
1✔
82
        ];
1✔
83
    }
84
}
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