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

lmc-eu / php-coding-standard / 8705023923

16 Apr 2024 11:46AM UTC coverage: 85.326% (+0.4%) from 84.916%
8705023923

Pull #83

github

web-flow
Merge 3de667f43 into aadd00026
Pull Request #83: Fix coveralls failing on build re-runs

157 of 184 relevant lines covered (85.33%)

48.55 hits per line

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

100.0
/src/Sniffs/Naming/AbstractClassNameSniff.php
1
<?php declare(strict_types=1);
2

3
/*
4
 * Originally part of https://github.com/symplify/symplify
5
 *
6
 * MIT License
7
 *
8
 * (c) 2020 Tomas Votruba <tomas.vot@gmail.com>
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in all
18
 * copies or substantial portions of the Software.
19
 *
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 * SOFTWARE.
27
 */
28

29
namespace Lmc\CodingStandard\Sniffs\Naming;
30

31
use Nette\Utils\Strings;
32
use PHP_CodeSniffer\Files\File;
33
use PHP_CodeSniffer\Sniffs\Sniff;
34

35
final class AbstractClassNameSniff implements Sniff
36
{
37
    /**
38
     * @var string
39
     */
40
    private const ERROR_MESSAGE = 'Abstract class should have prefix "Abstract".';
41

42
    /**
43
     * @var int
44
     */
45
    private $position;
46

47
    /**
48
     * @var File
49
     */
50
    private $file;
51

52
    /**
53
     * @return int[]
54
     */
55
    public function register(): array
56
    {
57
        return [T_CLASS];
30✔
58
    }
59

60
    /**
61
     * @param int $position
62
     */
63
    public function process(File $file, $position): void
64
    {
65
        $this->file = $file;
30✔
66
        $this->position = $position;
30✔
67

68
        if ($this->shouldBeSkipped()) {
30✔
69
            return;
30✔
70
        }
71

72
        $file->addError(self::ERROR_MESSAGE, $position, self::class);
15✔
73
    }
3✔
74

75
    private function shouldBeSkipped(): bool
76
    {
77
        $className = $this->getClassName();
30✔
78

79
        if (!$this->isClassAbstract() || $className === null) {
30✔
80
            return true;
15✔
81
        }
82

83
        return Strings::startsWith($className, 'Abstract');
30✔
84
    }
85

86
    private function isClassAbstract(): bool
87
    {
88
        $classProperties = $this->file->getClassProperties($this->position);
30✔
89

90
        return $classProperties['is_abstract'];
30✔
91
    }
92

93
    private function getClassName(): ?string
94
    {
95
        return $this->file->getDeclarationName($this->position);
30✔
96
    }
97
}
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