Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2892274
ArcanistInvalidDefaultParameterXHPASTLinterRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
ArcanistInvalidDefaultParameterXHPASTLinterRule.php
View Options
<?php
final
class
ArcanistInvalidDefaultParameterXHPASTLinterRule
extends
ArcanistXHPASTLinterRule
{
const
ID
=
70
;
public
function
getLintName
(
)
{
return
pht
(
'Invalid Default Parameter'
)
;
}
public
function
process
(
XHPASTNode
$root
)
{
$parameters
=
$root
->
selectDescendantsOfType
(
'n_DECLARATION_PARAMETER'
)
;
foreach
(
$parameters
as
$parameter
)
{
$type
=
$parameter
->
getChildByIndex
(
0
)
;
$default
=
$parameter
->
getChildByIndex
(
2
)
;
if
(
$type
->
getTypeName
(
)
==
'n_EMPTY'
)
{
continue
;
}
if
(
$default
->
getTypeName
(
)
==
'n_EMPTY'
)
{
continue
;
}
$default_is_null
=
$default
->
getTypeName
(
)
==
'n_SYMBOL_NAME'
&&
strtolower
(
$default
->
getConcreteString
(
)
)
==
'null'
;
switch
(
strtolower
(
$type
->
getConcreteString
(
)
)
)
{
case
'array'
:
if
(
$default
->
getTypeName
(
)
==
'n_ARRAY_LITERAL'
)
{
break
;
}
if
(
$default_is_null
)
{
break
;
}
$this
->
raiseLintAtNode
(
$default
,
pht
(
'Default value for parameters with `%s` type hint '
.
'can only be an `%s` or `%s`.'
,
'array'
,
'array'
,
'null'
)
)
;
break
;
case
'callable'
:
if
(
$default_is_null
)
{
break
;
}
$this
->
raiseLintAtNode
(
$default
,
pht
(
'Default value for parameters with `%s` type hint '
.
'can only be `%s`.'
,
'callable'
,
'null'
)
)
;
break
;
default
:
// Class/interface parameter.
if
(
$default_is_null
)
{
break
;
}
$this
->
raiseLintAtNode
(
$default
,
pht
(
'Default value for parameters with a class type hint '
.
'can only be `%s`.'
,
'null'
)
)
;
break
;
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 16:32 (2 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1120722
Default Alt Text
ArcanistInvalidDefaultParameterXHPASTLinterRule.php (1 KB)
Attached To
Mode
rARC Arcanist
Attached
Detach File
Event Timeline
Log In to Comment