Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7470812
MethodScopeSniff.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
MethodScopeSniff.php
View Options
<?php
/**
* Verifies that class methods have scope modifiers.
*
* @author Greg Sherwood <gsherwood@squiz.net>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/
namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope
;
use
PHP_CodeSniffer\Files\File
;
use
PHP_CodeSniffer\Sniffs\AbstractScopeSniff
;
use
PHP_CodeSniffer\Util\Tokens
;
class
MethodScopeSniff
extends
AbstractScopeSniff
{
/**
* Constructs a Squiz_Sniffs_Scope_MethodScopeSniff.
*/
public
function
__construct
()
{
parent
::
__construct
(
Tokens
::
$ooScopeTokens
,
[
T_FUNCTION
]);
}
//end __construct()
/**
* Processes the function tokens within the class.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param int $stackPtr The position where the token was found.
* @param int $currScope The current scope opener token.
*
* @return void
*/
protected
function
processTokenWithinScope
(
File
$phpcsFile
,
$stackPtr
,
$currScope
)
{
$tokens
=
$phpcsFile
->
getTokens
();
// Determine if this is a function which needs to be examined.
$conditions
=
$tokens
[
$stackPtr
][
'conditions'
];
end
(
$conditions
);
$deepestScope
=
key
(
$conditions
);
if
(
$deepestScope
!==
$currScope
)
{
return
;
}
$methodName
=
$phpcsFile
->
getDeclarationName
(
$stackPtr
);
if
(
$methodName
===
null
)
{
// Ignore closures.
return
;
}
$properties
=
$phpcsFile
->
getMethodProperties
(
$stackPtr
);
if
(
$properties
[
'scope_specified'
]
===
false
)
{
$error
=
'Visibility must be declared on method "%s"'
;
$data
=
[
$methodName
];
$phpcsFile
->
addError
(
$error
,
$stackPtr
,
'Missing'
,
$data
);
}
}
//end processTokenWithinScope()
/**
* Processes a token that is found within the scope that this test is
* listening to.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
* @param int $stackPtr The position in the stack where this
* token was found.
*
* @return void
*/
protected
function
processTokenOutsideScope
(
File
$phpcsFile
,
$stackPtr
)
{
}
//end processTokenOutsideScope()
}
//end class
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 07:50 (3 d, 22 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
27/0f/de1355a4ecf0b4968a9f6e08f090
Default Alt Text
MethodScopeSniff.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment