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

PHPCSStandards / PHP_CodeSniffer / 17483947696

05 Sep 2025 04:45AM UTC coverage: 78.507% (-0.7%) from 79.184%
17483947696

push

github

web-flow
Merge pull request #1213 from PHPCSStandards/feature/remove-filelist-tests

:fire: Hot Fix: remove FileList tests

25309 of 32238 relevant lines covered (78.51%)

73.81 hits per line

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

65.0
/src/Standards/MySource/Sniffs/Objects/DisallowNewWidgetSniff.php
1
<?php
2
/**
3
 * Ensures that widgets are not manually created.
4
 *
5
 * @author    Greg Sherwood <gsherwood@squiz.net>
6
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
7
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
 *
9
 * @deprecated 3.9.0
10
 */
11

12
namespace PHP_CodeSniffer\Standards\MySource\Sniffs\Objects;
13

14
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
15
use PHP_CodeSniffer\Sniffs\Sniff;
16
use PHP_CodeSniffer\Files\File;
17

18
class DisallowNewWidgetSniff implements Sniff, DeprecatedSniff
19
{
20

21

22
    /**
23
     * Returns an array of tokens this test wants to listen for.
24
     *
25
     * @return array<int|string>
26
     */
27
    public function register()
3✔
28
    {
29
        return [T_NEW];
3✔
30

31
    }//end register()
32

33

34
    /**
35
     * Processes this test, when one of its tokens is encountered.
36
     *
37
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
38
     * @param int                         $stackPtr  The position of the current token
39
     *                                               in the stack passed in $tokens.
40
     *
41
     * @return void
42
     */
43
    public function process(File $phpcsFile, $stackPtr)
3✔
44
    {
45
        $tokens = $phpcsFile->getTokens();
3✔
46

47
        $className = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
3✔
48
        if ($tokens[$className]['code'] !== T_STRING) {
3✔
49
            return;
×
50
        }
51

52
        if (substr(strtolower($tokens[$className]['content']), -10) === 'widgettype') {
3✔
53
            $widgetType = substr($tokens[$className]['content'], 0, -10);
3✔
54
            $error      = 'Manual creation of widget objects is banned; use Widget::getWidget(\'%s\'); instead';
3✔
55
            $data       = [$widgetType];
3✔
56
            $phpcsFile->addError($error, $stackPtr, 'Found', $data);
3✔
57
        }
1✔
58

59
    }//end process()
2✔
60

61

62
    /**
63
     * Provide the version number in which the sniff was deprecated.
64
     *
65
     * @return string
66
     */
67
    public function getDeprecationVersion()
×
68
    {
69
        return 'v3.9.0';
×
70

71
    }//end getDeprecationVersion()
72

73

74
    /**
75
     * Provide the version number in which the sniff will be removed.
76
     *
77
     * @return string
78
     */
79
    public function getRemovalVersion()
×
80
    {
81
        return 'v4.0.0';
×
82

83
    }//end getRemovalVersion()
84

85

86
    /**
87
     * Provide a custom message to display with the deprecation.
88
     *
89
     * @return string
90
     */
91
    public function getDeprecationMessage()
×
92
    {
93
        return 'The MySource standard will be removed completely in v4.0.0.';
×
94

95
    }//end getDeprecationMessage()
96

97

98
}//end class
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