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

lmc-eu / php-coding-standard / 9208833639

23 May 2024 01:23PM UTC coverage: 81.481% (-0.2%) from 81.651%
9208833639

push

github

OndraM
Feat: Remove SingleLineCommentSpacingFixer and MultilineStringToHeredocFixer from default checks, keep them suggested in README

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

85.19
/src/Helper/SniffClassWrapper.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\Helper;
30

31
use PHP_CodeSniffer\Files\File;
32
use SlevomatCodingStandard\Helpers\TokenHelper;
33

34
final class SniffClassWrapper
35
{
36
    public function __construct(private File $file, private int $position, private Naming $naming) {}
37

38
    public function getClassName(): ?string
40✔
39
    {
40
        return $this->naming->getClassName($this->file, $this->position + 2);
40✔
41
    }
42

43
    /**
44
     * @return string[]
45
     */
46
    public function getPartialInterfaceNames(): array
40✔
47
    {
48
        if (!$this->doesImplementInterface()) {
40✔
49
            return [];
30✔
50
        }
51

52
        $implementPosition = $this->getImplementsPosition();
10✔
53
        if (!is_int($implementPosition)) {
10✔
54
            return [];
×
55
        }
56

57
        $openBracketPosition = $this->file->findNext(T_OPEN_CURLY_BRACKET, $this->position, $this->position + 15);
10✔
58

59
        // anonymous class
60
        if (!$openBracketPosition) {
10✔
61
            return [];
×
62
        }
63

64
        $interfacePartialNamePosition = $this->file->findNext(T_STRING, $implementPosition, $openBracketPosition);
10✔
65

66
        $partialInterfacesNames = [];
10✔
67
        $partialInterfacesNames[] = $this->file->getTokens()[$interfacePartialNamePosition]['content'];
10✔
68

69
        return $partialInterfacesNames;
10✔
70
    }
71

72
    public function doesImplementInterface(): bool
40✔
73
    {
74
        return (bool) $this->getImplementsPosition();
40✔
75
    }
76

77
    public function doesExtendClass(): bool
×
78
    {
79
        return (bool) $this->file->findNext(T_EXTENDS, $this->position, $this->position + 5);
×
80
    }
81

82
    public function getParentClassName(): ?string
40✔
83
    {
84
        $extendsTokenPosition = TokenHelper::findNext($this->file, T_EXTENDS, $this->position, $this->position + 10);
40✔
85
        if ($extendsTokenPosition === null) {
40✔
86
            return null;
10✔
87
        }
88

89
        $parentClassPosition = (int) TokenHelper::findNext($this->file, T_STRING, $extendsTokenPosition);
30✔
90

91
        return $this->naming->getClassName($this->file, $parentClassPosition);
30✔
92
    }
93

94
    private function getImplementsPosition(): bool|int
40✔
95
    {
96
        return $this->file->findNext(T_IMPLEMENTS, $this->position, $this->position + 15);
40✔
97
    }
98
}
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