Skip to content

Synchronize this repo with Phan's changes and coding style #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use \Phan\Issue;

/**
* This configuration will be read and overlayed on top of the
* This configuration will be read and overlaid on top of the
* default configuration. Command line arguments will be applied
* after this file is read.
*
Expand Down
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ php:
- 7.0
- 7.1
- 7.2
- 7.3

dist: xenial

cache:
directories:
- $HOME/.composer/cache
- $HOME/.cache/phan-ast/build

before_install:
- ./tests/setup.sh
Expand All @@ -18,7 +22,7 @@ install:

# Install phan separately because the tolerant-php-parser version may be behind.
script:
- composer create-project phan/phan=0.12.4 ~/phan-install; ~/phan-install/phan
- composer create-project phan/phan=1.2.1 ~/phan-install; ~/phan-install/phan
- ./test

branches:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
},
"require": {
"php": ">=7.0",
"Microsoft/tolerant-php-parser": "0.0.12"
"Microsoft/tolerant-php-parser": "0.0.16"
},
"require-dev": {
"phpunit/phpunit": "^6.4"
},
"suggest": {
"ext-ast": "~0.1.5",
"phan/phan": "^1.0.0"
"ext-ast": "~0.1.5||~1.0.0",
"phan/phan": "^1.2.1"
},
"autoload": {
"psr-4": {"TolerantASTConverter\\": "src/TolerantASTConverter"}
Expand Down
93 changes: 76 additions & 17 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dump.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function dump_expr(string $expr) {
$ast_node = $parser->parseSourceFile($expr);
foreach ($ast_node->getDescendantNodes() as $descendant) {
// echo "unsetting " . get_class($descendant) . $descendant->getStart() . "\n";
unset($descendant->parent);
$descendant->parent = null;
}

$ast_node->parent = null;
Expand Down
56 changes: 56 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0"?>
<!-- This is a ruleset for https://github.com/squizlabs/PHP_CodeSniffer -->
<!-- Usage: phpcs.phar \-\-standard=path/toruleset.xml path/to/file_or_folder.php (Can't have double hyphen in xml comment) -->
<!-- phpcbf.phar can be used to automatically fix many issues -->
<!-- Use this with PHP_CodeSniffer 3.3.0 or newer -->
<!-- Source: https://github.com/phan/phan/blob/master/phpcs.xml -->
<ruleset name="Custom Standard">
<description>Coding standard for Phan</description>
<config name="installed_paths" value="../../slevomat/coding-standard"/>
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference" />
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment" />
<!-- TODO: Enable
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEmpty" />
-->
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash" />
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias" />
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
<property name="psr12Compatible" type="bool" value="true" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator" />
<rule ref="SlevomatCodingStandard.PHP.TypeCast" />
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon" />

<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" >
<properties>
<property name="spacesCountAroundEqualsSign" type="bool" value="false" />
</properties>
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceAfterDeclare" />
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceBetweenOpenTagAndDeclare" />
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectStrictTypesFormat" />
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints" />
<!-- <rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions" /> doesn't account for 'use function...' statements, don't use that -->
<!-- TODO: Look into SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing once PSR-12 is back into review -->

<!-- Look into SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification if it ever supports generic arrays+array shapes - Or just add this functionality to Phan's annotation plugin -->

<rule ref="PSR1" />
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength.TooLong" />
<!-- We put class initialization in the same file as methods -->
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR1.Classes.ClassDeclaration.MultipleClasses" />
</rule>

<rule ref="PSR12" />
<!-- Arbitrary increase of the line length limit -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="150"/>
<property name="absoluteLineLimit" value="200"/>
</properties>
</rule>
</ruleset>
6 changes: 3 additions & 3 deletions src/TolerantASTConverter/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

// Add the root to the include path
define('CLASS_DIR', __DIR__ . '/../');
set_include_path(get_include_path().PATH_SEPARATOR.CLASS_DIR);
set_include_path(get_include_path() . PATH_SEPARATOR . CLASS_DIR);

// Use the composer autoloader
foreach ([
__DIR__.'/../../vendor/autoload.php', // autoloader is in this project
__DIR__.'/../../../../../vendor/autoload.php', // autoloader is in parent project
__DIR__ . '/../../vendor/autoload.php', // autoloader is in this project
__DIR__ . '/../../../../../vendor/autoload.php', // autoloader is in parent project
] as $file) {
if (file_exists($file)) {
echo "Found the autoloader at $file\n";
Expand Down
3 changes: 1 addition & 2 deletions src/TolerantASTConverter/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace TolerantASTConverter;

use Error;
use function chr;
use function hexdec;
use function octdec;

use Error;

/**
* This class is based on code from https://github.com/nikic/PHP-Parser/blob/master/lib/PhpParser/Node/Scalar/String_.php
*
Expand Down
Loading