Skip to content
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

WIP: bears: Add PhanBear #1216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .ci/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ fi
sudo rm -rf $(which alex) # Delete ghc-alex as it clashes with npm deps
npm install

# Phan commands
git clone https://github.com/etsy/phan.git;
composer install;

# R commands
echo '.libPaths( c( "'"$R_LIB_USER"'", .libPaths()) )' >> .Rprofile
echo 'options(repos=structure(c(CRAN="http://cran.rstudio.com")))' >> .Rprofile
Expand Down
24 changes: 24 additions & 0 deletions bears/php/PhanBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from coalib.bearlib.abstractions.Linter import linter


@linter(executable='phan',
output_format='regex',
output_regex=r'(?P<filename>.+):(?P<line>\d+)\s(?P<message>.+)')
class PhanBear:
"""
Phan is a static analyzer for PHP that looks for common issues and will
verify type compatibility on various operations when type information is
available or can be deduced.

See <https://github.com/etsy/phan> for more information.
"""
LANGUAGES = {'PHP'}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Formatting', 'Syntax', 'Documentation',
'Code Simplification'}
ASCIINEMA_URL = ''

def create_argument(file, filename, config_file):
return (filename,)
23 changes: 23 additions & 0 deletions tests/php/PhanBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from coalib.testing.LocalBearTestHelper import verify_local_bear
from bears.php.PhanBear import PhanBear

bad_file_closure = '''<?php
$closure = function() {
return 42;
};
class A {
private $a = 42;
public function f() {
$b = 2;
$closure = function(int $p) use (&$b, $c) {
return ($p + $this->a + $b);
};
return $closure(3);
}
}
'''

PhanBearTest = verify_local_bear(
PhanBear,
valid_files=(),
invalid_files=(bad_file_closure,))