Skip to content

Instantly share code, notes, and snippets.

@padraic
Last active August 29, 2015 13:56

Revisions

  1. padraic revised this gist Feb 14, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion survey.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <?php

    define('PACKAGE_LIST', 'packages.txt');
    define('PACKAGE_LIST', 'list.txt');
    define('CODING_STANDARD', 'PSR2');
    define('SEVERITY', 1);
    define('ENCODING', 'utf-8');
  2. padraic revised this gist Feb 12, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions survey.php
    Original file line number Diff line number Diff line change
    @@ -73,8 +73,8 @@
    foreach ($paths as $name => $path) {
    $i++;
    $report_name = str_replace('/', '.', $name);
    $options[] = '--report-source=./' . $reports_dir . '/' . $report_name . '.source.txt';
    $options[] = '--report-csv=./' . $reports_dir . '/' . $report_name . '.csv';
    $options['source'] = '--report-source=./' . $reports_dir . '/' . $report_name . '.source.txt';
    $options['csv'] = '--report-csv=./' . $reports_dir . '/' . $report_name . '.csv';
    echo "\n" . 'Setting the Sniffer on ' . $name . ' (' . $i . ' of ' . $count . ")\n\n";
    $command = 'phpcs ' . implode(' ', $options) . ' ' . $path;
    echo $command . "\n\n";
  3. padraic revised this gist Feb 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion survey.php
    Original file line number Diff line number Diff line change
    @@ -63,7 +63,7 @@
    '--severity=' . SEVERITY,
    '--encoding=' . ENCODING,
    '--report=' . REPORT,
    '--extensions' . EXTENSIONS,
    '--extensions=' . EXTENSIONS,
    ];

    $reports_dir = 'reports-' . time();
  4. padraic revised this gist Feb 12, 2014. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions survey.php
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,7 @@
    define('SEVERITY', 1);
    define('ENCODING', 'utf-8');
    define('REPORT', 'source');
    define('EXTENSIONS', 'php');
    $excluded = [
    '*/test/*',
    '*/tests/*',
    @@ -13,7 +14,13 @@
    '*/doc/*',
    '*/docs/*',
    '*/build/*',
    '*/data/*'
    '*/data/*',
    '*/resource/*',
    '*/resources/*',
    '*/bin/*',
    '*/script/*',
    '*/scripts/*',
    '*/ext/*',
    ];

    if (file_exists('composer.phar')) {
    @@ -51,11 +58,12 @@
    }

    $options = [
    ' --ignore=' . implode(',', $excluded),
    ' --standard=' . CODING_STANDARD,
    ' --severity=' . SEVERITY,
    ' --encoding=' . ENCODING,
    ' --report=' . REPORT,
    '--ignore=' . implode(',', $excluded),
    '--standard=' . CODING_STANDARD,
    '--severity=' . SEVERITY,
    '--encoding=' . ENCODING,
    '--report=' . REPORT,
    '--extensions' . EXTENSIONS,
    ];

    $reports_dir = 'reports-' . time();
    @@ -68,7 +76,7 @@
    $options[] = '--report-source=./' . $reports_dir . '/' . $report_name . '.source.txt';
    $options[] = '--report-csv=./' . $reports_dir . '/' . $report_name . '.csv';
    echo "\n" . 'Setting the Sniffer on ' . $name . ' (' . $i . ' of ' . $count . ")\n\n";
    $command = 'phpcs' . implode(' ', $options) . ' ' . $path;
    $command = 'phpcs ' . implode(' ', $options) . ' ' . $path;
    echo $command . "\n\n";
    passthru($command);
    }
  5. padraic revised this gist Feb 12, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion survey.php
    Original file line number Diff line number Diff line change
    @@ -68,5 +68,7 @@
    $options[] = '--report-source=./' . $reports_dir . '/' . $report_name . '.source.txt';
    $options[] = '--report-csv=./' . $reports_dir . '/' . $report_name . '.csv';
    echo "\n" . 'Setting the Sniffer on ' . $name . ' (' . $i . ' of ' . $count . ")\n\n";
    passthru('phpcs ' . implode(' ', $options) . ' ' . $path);
    $command = 'phpcs' . implode(' ', $options) . ' ' . $path;
    echo $command . "\n\n";
    passthru($command);
    }
  6. padraic created this gist Feb 12, 2014.
    72 changes: 72 additions & 0 deletions survey.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    <?php

    define('PACKAGE_LIST', 'packages.txt');
    define('CODING_STANDARD', 'PSR2');
    define('SEVERITY', 1);
    define('ENCODING', 'utf-8');
    define('REPORT', 'source');
    $excluded = [
    '*/test/*',
    '*/tests/*',
    '*/example/*',
    '*/examples/*',
    '*/doc/*',
    '*/docs/*',
    '*/build/*',
    '*/data/*'
    ];

    if (file_exists('composer.phar')) {
    passthru('php composer.phar self-update');
    } else {
    passthru('curl -sS https://getcomposer.org/installer | php');
    }

    if (!file_exists('composer.lock') || !file_exists('composer.json')) {
    $packages_required = '';
    $handle = fopen(PACKAGE_LIST, "r");
    while(fscanf($handle, "%s", $package_name)) {
    $packages_required .= ' ' . $package_name . ':dev-master';
    }
    fclose($handle);
    passthru('php composer.phar require --prefer-dist' . $packages_required);
    } else {
    passthru('php composer.phar update');
    }

    $paths = [];
    $installed = json_decode(file_get_contents('./vendor/composer/installed.json'), true);
    foreach($installed as $package) {
    $fullpath = './vendor/' . $package['name'];
    if (isset($package['autoload']['psr-0'])) {
    foreach($package['autoload']['psr-0'] as $ns => $path) {
    if (strlen($path) == 0) {
    $fullpath .= '/' . str_replace('\\', '/', $ns);
    } else {
    $fullpath .= '/' . $path;
    }
    $paths[$package['name']] = $fullpath;
    }
    }
    }

    $options = [
    ' --ignore=' . implode(',', $excluded),
    ' --standard=' . CODING_STANDARD,
    ' --severity=' . SEVERITY,
    ' --encoding=' . ENCODING,
    ' --report=' . REPORT,
    ];

    $reports_dir = 'reports-' . time();
    mkdir($reports_dir);
    $count = count($paths);
    $i = 0;
    foreach ($paths as $name => $path) {
    $i++;
    $report_name = str_replace('/', '.', $name);
    $options[] = '--report-source=./' . $reports_dir . '/' . $report_name . '.source.txt';
    $options[] = '--report-csv=./' . $reports_dir . '/' . $report_name . '.csv';
    echo "\n" . 'Setting the Sniffer on ' . $name . ' (' . $i . ' of ' . $count . ")\n\n";
    passthru('phpcs ' . implode(' ', $options) . ' ' . $path);
    }