1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-08 16:02:39 +01:00

Let arc liberate throw on unsupported PHP features

Summary: Ref T4725.

Test Plan: add some files that have unsupported constructs all over the place and run `arc liberate`

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T4725

Differential Revision: https://secure.phabricator.com/D9585
This commit is contained in:
Richard van Velzen 2014-06-17 05:13:05 -07:00 committed by epriestley
parent 3201239e85
commit 3810cdbbcc

View file

@ -77,6 +77,32 @@ $root = $tree->getRootNode();
$root->buildSelectCache(); $root->buildSelectCache();
// -( Unsupported Constructs )------------------------------------------------
$namespaces = $root->selectDescendantsOfType('n_NAMESPACE');
foreach ($namespaces as $namespace) {
phutil_fail_on_unsupported_feature(
$namespace, $path, pht('namespaces'));
}
$uses = $root->selectDescendantsOfType('n_USE');
foreach ($namespaces as $namespace) {
phutil_fail_on_unsupported_feature(
$namespace, $path, pht('namespace `use` statements'));
}
$possible_traits = $root->selectDescendantsOfType('n_CLASS_DECLARATION');
foreach ($possible_traits as $possible_trait) {
$attributes = $possible_trait->getChildByIndex(0);
// can't use getChildByIndex here because not all classes have attributes
foreach ($attributes->getChildren() as $attribute) {
if (strtolower($attribute->getConcreteString()) == 'trait') {
phutil_fail_on_unsupported_feature(
$possible_trait, $path, pht('traits'));
}
}
}
// -( Marked Externals )------------------------------------------------------ // -( Marked Externals )------------------------------------------------------
@ -459,6 +485,24 @@ if ($args->getArg('ugly')) {
// -( Library )--------------------------------------------------------------- // -( Library )---------------------------------------------------------------
function phutil_fail_on_unsupported_feature(XHPASTNode $node, $file, $what) {
$line = $node->getLineNumber();
$message = phutil_console_wrap(pht(
"`arc liberate` has limited support for features introduced after PHP ".
"5.2.3. This library uses an unsupported feature (%s) on line %d of %s",
$what,
$line,
Filesystem::readablePath($file)));
$result = array(
'error' => $message,
'line' => $line,
'file' => $file,
);
$json = new PhutilJSON();
echo $json->encodeFormatted($result);
exit(0);
}
function phutil_symbols_get_builtins() { function phutil_symbols_get_builtins() {
$builtin = array(); $builtin = array();