Skip to content

Commit

Permalink
bears: Add PhanBear
Browse files Browse the repository at this point in the history
  • Loading branch information
AsnelChristian committed Dec 27, 2016
1 parent c8ddbaa commit b4f9235
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
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,))

0 comments on commit b4f9235

Please sign in to comment.