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

lmc-eu / php-coding-standard / 9266536217

28 May 2024 09:04AM UTC coverage: 81.481%. Remained the same
9266536217

Pull #109

github

web-flow
Merge 580967a4c into 11a7ba3a3
Pull Request #109: Fix: Disable incorrectly behaving PhpdocAlignFixer for multiline descriptions

176 of 216 relevant lines covered (81.48%)

16.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 PHP_CodeSniffer\Files\File;
32
use PHP_CodeSniffer\Sniffs\Sniff;
33

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

41
    private int $position;
42
    private File $file;
43

44
    /**
45
     * @return int[]
46
     */
47
    public function register(): array
10✔
48
    {
49
        return [T_CLASS];
10✔
50
    }
51

52
    public function process(File $phpcsFile, $stackPtr): void
10✔
53
    {
54
        $this->file = $phpcsFile;
10✔
55
        $this->position = $stackPtr;
10✔
56

57
        if ($this->shouldBeSkipped()) {
10✔
58
            return;
10✔
59
        }
60

61
        $phpcsFile->addError(self::ERROR_MESSAGE, $stackPtr, self::class);
5✔
62
    }
63

64
    private function shouldBeSkipped(): bool
10✔
65
    {
66
        $className = $this->getClassName();
10✔
67

68
        if (!$this->isClassAbstract() || $className === null) {
10✔
69
            return true;
5✔
70
        }
71

72
        return str_starts_with($className, 'Abstract');
10✔
73
    }
74

75
    private function isClassAbstract(): bool
10✔
76
    {
77
        $classProperties = $this->file->getClassProperties($this->position);
10✔
78

79
        return $classProperties['is_abstract'];
10✔
80
    }
81

82
    private function getClassName(): ?string
10✔
83
    {
84
        return $this->file->getDeclarationName($this->position);
10✔
85
    }
86
}
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