Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22417498
ArcanistInvalidDefaultParameterXHPASTLinterRule.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
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
Sat, Nov 28, 02:06 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1209172
Default Alt Text
ArcanistInvalidDefaultParameterXHPASTLinterRule.php (1 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline