• 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/SetTemplateDisallowedForBlockRule.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
 * Do not use setTemplate in Block classes, see
26
 * https://github.com/extdn/extdn-phpcs/blob/master/Extdn/Sniffs/Blocks/SetTemplateInBlockSniff.md
27
 *
28
 * @implements Rule<MethodCall>
29
 */
30
class SetTemplateDisallowedForBlockRule implements Rule
31
{
32
    /**
33
     * @phpstan-return class-string<MethodCall>
34
     * @return string
35
     */
36
    public function getNodeType(): string
37
    {
38
        return MethodCall::class;
2✔
39
    }
40

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

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

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

57
        return [
1✔
58
            RuleErrorBuilder::message(
1✔
59
                sprintf(
1✔
60
                    'Setter methods like %s::%s() are deprecated in Block classes, use constructor arguments instead',
1✔
61
                    $type->describe(VerbosityLevel::typeOnly()),
1✔
62
                    $node->name->name
1✔
63
                )
1✔
64
            )
1✔
65
            ->identifier('bitExpertMagento.setTemplateDisallowedForBlock')
1✔
66
            ->build()
1✔
67
        ];
1✔
68
    }
69
}
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

© 2026 Coveralls, Inc