def execute(): output_start('phpcs') dirs = get_dirs() phpcs_standard = dirs['project'] + get_value('phpcs-standard') check_dir = get_value('check-dir') exclude_dirs = [] for exclude_dir in get_value('exclude-dirs'): exclude_dirs.append(exclude_dir + '/*') excludes = ','.join(exclude_dirs) if excludes != '': excludes = '--ignore=' + excludes if not os.path.isfile(phpcs_standard): print( '>>> No phpcs-standard found. Fallback is the default move-elevator/symfony-coding-standard:' ) phpcs_standard = get_value( 'checker-dir' ) + 'vendor/move-elevator/symfony-coding-standard/Standards/Symfony2' print('>>> phpcs standard: ' + phpcs_standard) print('>>> Excludes: ' + excludes) code = php( 'phpcs', '--standard=' + phpcs_standard + ' --extensions=php --report-checkstyle=' + check_dir + 'checkstyle.xml ' + excludes + ' ' + dirs['scan']) if code == 512: output_error('There was a error/exception while executing phpcs.')
def execute(): output_start('phpcs') dirs = get_dirs() phpcs_standard = dirs['project']+get_value('phpcs-standard') check_dir = get_value('check-dir') exclude_dirs = [] for exclude_dir in get_value('exclude-dirs'): exclude_dirs.append(exclude_dir+'/*') excludes = ','.join(exclude_dirs) if excludes != '': excludes = '--ignore='+excludes if not os.path.isfile(phpcs_standard): print('>>> No phpcs-standard found. Fallback is the default move-elevator/symfony-coding-standard:') phpcs_standard = get_value('checker-dir')+'vendor/move-elevator/symfony-coding-standard/Standards/Symfony2' print('>>> phpcs standard: '+phpcs_standard) print('>>> Excludes: '+excludes) code = php('phpcs', '--standard='+phpcs_standard+' --extensions=php --report-checkstyle='+check_dir+'checkstyle.xml '+excludes+' '+dirs['scan']) if code == 512: output_error('There was a error/exception while executing phpcs.')
def execute(): output_start('coverfish') phpunit_xml = get_value('project-dir')+get_value('phpunit-xml') phpunit_xml_folder = os.path.dirname(phpunit_xml) root = xml.etree.ElementTree.parse(phpunit_xml).getroot() output_level = get_value('coverfish-output-level') bootstrap = root.get('bootstrap', False) if bootstrap is False: output_error('You have to define the bootstrap attribute in you phpunit.yml in the root node.') autoload = phpunit_xml_folder+'/'+bootstrap for testsuites in root.findall('testsuites'): for testsuite in testsuites: for directory in testsuite: scan_path = phpunit_xml_folder+'/'+directory.text if not os.path.isdir(scan_path): output_error('Only directories are supported in the phpunit.xml in the testsuites.') print('>>> coverfish scan path: '+scan_path) print('>>> coverfish autoload file: '+autoload) code = php('coverfish', 'scan --raw-scan-path='+scan_path+' --raw-autoload-file='+autoload+' --output-level='+output_level+' --no-ansi') if code != 0: output_error('The coverfish command failed with the code '+str(code))
def get_test_argument(check_dir): phpunit_xml = get_value('project-dir') + get_value('phpunit-xml') phpunit_junit_xml = check_dir + 'phpunit.xml' print('>>> phpunit.xml configuration: ' + phpunit_xml) print('>>> JUnit phpunit.xml log: ' + phpunit_xml) return '--configuration ' + phpunit_xml + ' --debug --log-junit ' + phpunit_junit_xml
def get_test_argument(check_dir): phpunit_xml = get_value('project-dir')+get_value('phpunit-xml') phpunit_junit_xml = check_dir+'phpunit.xml' print('>>> phpunit.xml configuration: '+phpunit_xml) print('>>> JUnit phpunit.xml log: '+phpunit_xml) return '--configuration '+phpunit_xml+' --debug --log-junit '+phpunit_junit_xml
def get_dirs(): project_dir = get_value('project-dir') scan_dir = project_dir+get_value('scan-dir') print('>>> Project dir: '+project_dir) print('>>> Scan dir: '+scan_dir) return {'project': project_dir, 'scan': scan_dir}
def get_dirs(): project_dir = get_value('project-dir') scan_dir = project_dir + get_value('scan-dir') print('>>> Project dir: ' + project_dir) print('>>> Scan dir: ' + scan_dir) return {'project': project_dir, 'scan': scan_dir}
def php(command, arguments): project_dir = get_value('project-dir') bin_dir = get_value('bin-dir') execution_command = get_full_dir(project_dir + bin_dir) + command if not os.path.isfile(execution_command): execution_command = get_value('checker-dir') + 'bin/' + command command = get_value('php') + ' ' + execution_command + ' ' + arguments print('>>> Execute command: ' + command) return os.system(command)
def php(command, arguments): project_dir = get_value('project-dir') bin_dir = get_value('bin-dir') execution_command = get_full_dir(project_dir+bin_dir)+command if not os.path.isfile(execution_command): execution_command = get_value('checker-dir')+'bin/'+command command = get_value('php')+' '+execution_command+' '+arguments print('>>> Execute command: '+command) return os.system(command)
def execute(): output_start('phpunit') check_dir = get_value('check-dir') argument = get_test_argument(check_dir) if get_value('phpunit-coverage') == 'true': argument = argument+get_coverage_argument(check_dir) code = php('phpunit', argument) if code != 0: output_error('Some tests failed.')
def execute(): output_start('phpunit') check_dir = get_value('check-dir') argument = get_test_argument(check_dir) if get_value('phpunit-coverage') == 'true': argument = argument + get_coverage_argument(check_dir) code = php('phpunit', argument) if code != 0: output_error('Some tests failed.')
def execute(): output_start('phpcpd') dirs = get_dirs() check_dir = get_value('check-dir') exclude_dirs = get_value('exclude-dirs') excludes = '' for exclude in exclude_dirs: excludes = excludes+' --exclude '+exclude print('>>> Excludes: '+excludes) php('phpcpd', excludes+' --log-pmd '+check_dir+'pmd-cpd.xml '+dirs['scan'])
def execute(): output_start('phpcpd') dirs = get_dirs() check_dir = get_value('check-dir') exclude_dirs = get_value('exclude-dirs') excludes = '' for exclude in exclude_dirs: excludes = excludes + ' --exclude ' + exclude print('>>> Excludes: ' + excludes) php('phpcpd', excludes + ' --log-pmd ' + check_dir + 'pmd-cpd.xml ' + dirs['scan'])
def initialization(): checker_dir = get_value('checker-dir') for file_bin, url in download_dict.items(): absolute_file_bin = checker_dir+file_bin if not os.path.isfile(absolute_file_bin): download(absolute_file_bin, url)
def initialization(): checker_dir = get_value('checker-dir') if not os.path.isfile(checker_dir+'bin/composer'): download(checker_dir) if not os.path.isfile(checker_dir+'bin/phpcs'): composer('install')
def composer(arguments): base_dir = os.getcwd() os.chdir(get_value('checker-dir')) php('composer', arguments) os.chdir(base_dir)
def metric(): metric_dir = configuration.get_value('build-dir') + 'metric/' configuration.add('metric-dir', metric_dir) initialization.prepare_dir(metric_dir) phploc.execute() phpmetrics.execute() pdepend.execute()
def execute(): output_start('pdepend') metric_dir = get_value('metric-dir') scan_dir = get_value('project-dir')+get_value('scan-dir') excludes = ','.join(get_value('exclude-dirs')) if excludes != '': excludes = '--ignore='+excludes print('>>> Metric dir: '+metric_dir) print('>>> Excludes: '+excludes) code = php('pdepend', '--summary-xml='+metric_dir+'pdepend.xml --overview-pyramid='+metric_dir+'pdepend.svg --jdepend-chart='+metric_dir+'dependencies.svg '+excludes+' '+scan_dir) if code != 0: output_error('There was a error/exception while executing pdepend.')
def execute(): output_start('phpmetrics') metric_dir = get_value('metric-dir') scan_dir = get_value('project-dir')+get_value('scan-dir') excludes = '|'.join(get_value('exclude-dirs')) if excludes != '': excludes = '--excluded-dirs="'+excludes+'"' print('>>> Metric dir: '+metric_dir) print('>>> Excludes: '+excludes) code = php('phpmetrics.phar', '--extensions=php --report-xml='+metric_dir+'phpmetrics.xml --report-html='+metric_dir+'phpmetrics.html '+excludes+' '+scan_dir) if code != 0: output_error('There was a error/exception while executing phpmetrics.')
def metric(): metric_dir = configuration.get_value('build-dir')+'metric/' configuration.add('metric-dir', metric_dir) initialization.prepare_dir(metric_dir) phploc.execute() phpmetrics.execute() pdepend.execute()
def execute(): output_start('phploc') metric_dir = get_value('metric-dir') scan_dir = get_value('project-dir')+get_value('scan-dir') exclude_dirs = get_value('exclude-dirs') excludes = '' for exclude in exclude_dirs: excludes = excludes+' --exclude '+exclude print('>>> Metric dir: '+metric_dir) print('>>> Excludes: '+excludes) code = php('phploc', '--count-tests --log-csv '+metric_dir+'phploc.csv --log-xml '+metric_dir+'phploc.xml '+excludes+' '+scan_dir) if code != 0: output_error('There was a error/exception while executing phploc.')
def execute(): output_start('security-checker') composer_lock = get_value('project-dir')+'composer.lock' print('>>> composer.lock: '+composer_lock) code = php('security-checker.phar', 'security:check '+composer_lock) if code != 0: output_error('You have a security issue with your composer.lock')
def execute(): output_start('security-checker') composer_lock = get_value('project-dir') + 'composer.lock' print('>>> composer.lock: ' + composer_lock) code = php('security-checker.phar', 'security:check ' + composer_lock) if code != 0: output_error('You have a security issue with your composer.lock')
def execute(): output_start('phpmetrics') metric_dir = get_value('metric-dir') scan_dir = get_value('project-dir') + get_value('scan-dir') excludes = '|'.join(get_value('exclude-dirs')) if excludes != '': excludes = '--excluded-dirs="' + excludes + '"' print('>>> Metric dir: ' + metric_dir) print('>>> Excludes: ' + excludes) code = php( 'phpmetrics.phar', '--extensions=php --report-xml=' + metric_dir + 'phpmetrics.xml --report-html=' + metric_dir + 'phpmetrics.html ' + excludes + ' ' + scan_dir) if code != 0: output_error('There was a error/exception while executing phpmetrics.')
def execute(): output_start('pdepend') metric_dir = get_value('metric-dir') scan_dir = get_value('project-dir') + get_value('scan-dir') excludes = ','.join(get_value('exclude-dirs')) if excludes != '': excludes = '--ignore=' + excludes print('>>> Metric dir: ' + metric_dir) print('>>> Excludes: ' + excludes) code = php( 'pdepend', '--summary-xml=' + metric_dir + 'pdepend.xml --overview-pyramid=' + metric_dir + 'pdepend.svg --jdepend-chart=' + metric_dir + 'dependencies.svg ' + excludes + ' ' + scan_dir) if code != 0: output_error('There was a error/exception while executing pdepend.')
def execute(): output_start('lint') dirs = get_dirs() exclude_dirs = get_value('exclude-dirs') forbidden_methods = get_value('forbidden-methods') print('>>> Excludes dirs: ', exclude_dirs) print('>>> Forbidden methods: ', forbidden_methods) for root, dirs, files in os.walk(dirs['scan']): for exclude in exclude_dirs: if exclude in dirs: dirs.remove(exclude) for file in files: if file.endswith(".php"): php_file = os.path.join(root, file) code = os.system(get_value('php')+' -l '+php_file) if code != 0: output_error('PHP lint found an error in the file '+php_file) check_forbidden_methods(forbidden_methods, php_file)
def execute(): output_start('phploc') metric_dir = get_value('metric-dir') scan_dir = get_value('project-dir') + get_value('scan-dir') exclude_dirs = get_value('exclude-dirs') excludes = '' for exclude in exclude_dirs: excludes = excludes + ' --exclude ' + exclude print('>>> Metric dir: ' + metric_dir) print('>>> Excludes: ' + excludes) code = php( 'phploc', '--count-tests --log-csv ' + metric_dir + 'phploc.csv --log-xml ' + metric_dir + 'phploc.xml ' + excludes + ' ' + scan_dir) if code != 0: output_error('There was a error/exception while executing phploc.')
def execute(): output_start('phpmd') dirs = get_dirs() phpmd_xml = dirs['project']+get_value('phpmd-xml') check_dir = get_value('check-dir') excludes = ','.join(get_value('exclude-dirs')) if excludes != '': excludes = '--exclude '+excludes if not os.path.isfile(phpmd_xml): print('>>> No phpmd-xml found. Fallback is the default phpmd.xml:') phpmd_xml = get_value('checker-dir')+'data/phpmd.xml.dist' print('>>> phpmd.xml: '+phpmd_xml) print('>>> Excludes: '+excludes) code = php('phpmd', dirs['scan']+' xml '+phpmd_xml+' --reportfile '+check_dir+'pmd.xml '+excludes) if code == 1: output_error('There was a error/exception while executing phpmd.')
def execute(): output_start('coverfish') phpunit_xml = get_value('project-dir') + get_value('phpunit-xml') phpunit_xml_folder = os.path.dirname(phpunit_xml) root = xml.etree.ElementTree.parse(phpunit_xml).getroot() output_level = get_value('coverfish-output-level') bootstrap = root.get('bootstrap', False) if bootstrap is False: output_error( 'You have to define the bootstrap attribute in you phpunit.yml in the root node.' ) autoload = phpunit_xml_folder + '/' + bootstrap for testsuites in root.findall('testsuites'): for testsuite in testsuites: for directory in testsuite: scan_path = phpunit_xml_folder + '/' + directory.text if not os.path.isdir(scan_path): output_error( 'Only directories are supported in the phpunit.xml in the testsuites.' ) print('>>> coverfish scan path: ' + scan_path) print('>>> coverfish autoload file: ' + autoload) code = php( 'coverfish', 'scan --raw-scan-path=' + scan_path + ' --raw-autoload-file=' + autoload + ' --output-level=' + output_level + ' --no-ansi') if code != 0: output_error( 'The coverfish command failed with the code ' + str(code))
def execute(): output_start('phpmd') dirs = get_dirs() phpmd_xml = dirs['project'] + get_value('phpmd-xml') check_dir = get_value('check-dir') excludes = ','.join(get_value('exclude-dirs')) if excludes != '': excludes = '--exclude ' + excludes if not os.path.isfile(phpmd_xml): print('>>> No phpmd-xml found. Fallback is the default phpmd.xml:') phpmd_xml = get_value('checker-dir') + 'data/phpmd.xml.dist' print('>>> phpmd.xml: ' + phpmd_xml) print('>>> Excludes: ' + excludes) code = php( 'phpmd', dirs['scan'] + ' xml ' + phpmd_xml + ' --reportfile ' + check_dir + 'pmd.xml ' + excludes) if code == 1: output_error('There was a error/exception while executing phpmd.')
def prepare_check(): check_dir = configuration.get_value('build-dir')+'check/' configuration.add('check-dir', check_dir) initialization.prepare_dir(check_dir) composer.project_installation()
def prepare_check(): check_dir = configuration.get_value('build-dir') + 'check/' configuration.add('check-dir', check_dir) initialization.prepare_dir(check_dir) composer.project_installation()
def get_coverage_argument(check_dir): base_dir = get_value('build-dir') print('>>> With coverage and crap index') return ' --coverage-html '+base_dir+'coverage --coverage-clover '+check_dir+'coverage.xml --coverage-crap4j '+check_dir+'crap4j.xml'
def get_coverage_argument(check_dir): base_dir = get_value('build-dir') print('>>> With coverage and crap index') return ' --coverage-html ' + base_dir + 'coverage --coverage-clover ' + check_dir + 'coverage.xml --coverage-crap4j ' + check_dir + 'crap4j.xml'
def download(checker_dir): php_bin = get_value('php') if not os.path.exists(checker_dir+'bin'): os.makedirs(checker_dir+'bin') print('>>> Download composer') os.system('curl -sS https://getcomposer.org/installer | '+php_bin+' -- --install-dir='+checker_dir+'bin --filename=composer')