Skip to content

Commit

Permalink
PHPStanBear: Add PHPStanBear
Browse files Browse the repository at this point in the history
Introduce PHPStanBear
Checks the code with ``phpstan analyze``.
Closes #1426
  • Loading branch information
damngamerz committed Feb 28, 2017
1 parent 8575b3f commit 00e1649
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bears/php/PHPStanBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from coalib.bearlib.abstractions.Linter import linter


@linter(executable='phpstan',
output_format='regex',
output_regex=r'(?P<line>\d+) (?P<message>.*)')
class PHPStanBear:
"""
Checks the code with ``phpstan analyze``.
This can run it on multiple files and folders.
See <https://github.com/phpstan/phpstan> for more information.
"""
LANGUAGES = {'PHP'}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Syntax'}

@staticmethod
def create_arguments(filename, file, config_file):
return ('analyse', '--no-ansi', filename)
36 changes: 36 additions & 0 deletions tests/php/PHPStanBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
from queue import Queue
from shutil import which
from unittest.case import skipIf

from bears.php.PHPStanBear import PHPStanBear
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
from coalib.settings.Section import Section


@skipIf(which('phpstan') is None, 'PHPStan is not installed')
class PHPStanBearTest(LocalBearTestHelper):

def setUp(self):
self.section = Section('test section')
self.uut = PHPStanBear(self.section, Queue())
self.test_file1 = os.path.join(os.path.dirname(__file__),
'test_files',
'phplint_test1.php')
self.test_file2 = os.path.join(os.path.dirname(__file__),
'test_files',
'phplint_test2.php')

def test_run(self):
# Test a file with errors and warnings
self.check_validity(
self.uut,
[],
self.test_file1,
valid=False)

# Test a file without any issues
self.check_validity(
self.uut,
[],
self.test_file2)

0 comments on commit 00e1649

Please sign in to comment.