Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 12a0942

Browse files
authored
Update PHP Codesniffer (#83)
* Update PHP Codesniffer * Update circleci
1 parent 8b7d12e commit 12a0942

File tree

7 files changed

+261
-190
lines changed

7 files changed

+261
-190
lines changed

.circleci/config.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2.1
2+
3+
jobs:
4+
build:
5+
machine:
6+
docker_layer_caching: true
7+
working_directory: ~/codeclimate/codeclimate-phpcodesniffer
8+
steps:
9+
- checkout
10+
- run:
11+
name: Build
12+
command: make image
13+
notify:
14+
webhooks:
15+
- url: https://cc-slack-proxy.herokuapp.com/circle

Dockerfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:edge
1+
FROM alpine:3.12
22

33
RUN adduser -u 9000 -D app
44

@@ -20,15 +20,9 @@ RUN apk add --no-cache \
2020
php7-tokenizer \
2121
php7-xml \
2222
php7-xmlwriter \
23-
php7-zlib && \
24-
EXPECTED_SIGNATURE=$(php -r "echo file_get_contents('https://composer.github.io/installer.sig');") && \
25-
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
26-
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');") && \
27-
[ "$EXPECTED_SIGNATURE" = "$ACTUAL_SIGNATURE" ] || (echo "Invalid Composer installer signature"; exit 1) && \
28-
php composer-setup.php --quiet && \
29-
mv composer.phar /usr/local/bin/composer && \
30-
rm -r composer-setup.php ~/.composer
23+
php7-zlib
3124

25+
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
3226
COPY composer.json composer.lock ./
3327

3428
RUN apk add --no-cache git && \

Runner.php renamed to Executor.php

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

3-
use PHP_CodeSniffer\Files\FileList;
3+
use Stringy\Stringy as S;
4+
use PHP_CodeSniffer\Runner;
5+
use PHP_CodeSniffer\Config;
46
use PHP_CodeSniffer\Reporter;
7+
use PHP_CodeSniffer\Files\DummyFile;
58
use PHP_CodeSniffer\Util\Timing;
6-
use PHP_CodeSniffer\Config;
7-
use Stringy\Stringy as S;
89

9-
class Runner
10+
class Executor
1011
{
1112
const DEFAULT_EXTENSIONS = array("php", "inc", "module");
1213

@@ -23,7 +24,7 @@ public function queueDirectory($dir, $prefix = '')
2324
{
2425
chdir("/code");
2526

26-
if(isset($this->config['include_paths'])) {
27+
if (isset($this->config['include_paths'])) {
2728
$this->queueWithIncludePaths();
2829
} else {
2930
$this->queuePaths($dir, $prefix, $this->config['exclude_paths']);
@@ -32,7 +33,8 @@ public function queueDirectory($dir, $prefix = '')
3233
$this->server->process_work(false);
3334
}
3435

35-
public function queueWithIncludePaths() {
36+
public function queueWithIncludePaths()
37+
{
3638
foreach ($this->config['include_paths'] as $f) {
3739
if ($f !== '.' and $f !== '..') {
3840
if (is_dir($f)) {
@@ -44,7 +46,8 @@ public function queueWithIncludePaths() {
4446
}
4547
}
4648

47-
public function queuePaths($dir, $prefix = '', $exclusions = []) {
49+
public function queuePaths($dir, $prefix = '', $exclusions = [])
50+
{
4851
$dir = rtrim($dir, '\\/');
4952

5053
foreach (scandir($dir) as $f) {
@@ -62,7 +65,8 @@ public function queuePaths($dir, $prefix = '', $exclusions = []) {
6265
}
6366
}
6467

65-
public function filterByExtension($f, $prefix = '') {
68+
public function filterByExtension($f, $prefix = '')
69+
{
6670
foreach ($this->fileExtensions() as $file_extension) {
6771
if (S::create($f)->endsWith($file_extension)) {
6872
$prefix = ltrim($prefix, "\\/");
@@ -71,7 +75,8 @@ public function filterByExtension($f, $prefix = '') {
7175
}
7276
}
7377

74-
private function fileExtensions() {
78+
private function fileExtensions()
79+
{
7580
$extensions = $this->config['config']['file_extensions'];
7681

7782
if (empty($extensions)) {
@@ -85,55 +90,44 @@ public function run($files)
8590
{
8691
try {
8792
$resultFile = tempnam(sys_get_temp_dir(), 'phpcodesniffer');
93+
$config_args = array( '-s', '-p' );
8894

89-
$extra_config_options = array('--report-json='.$resultFile);
95+
if (isset($this->config['config']['ignore_warnings']) && $this->config['config']['ignore_warnings']) {
96+
$config_args[] = '-n';
97+
}
98+
99+
Timing::startTiming();
100+
101+
$runner = new Runner();
102+
$runner->config = new Config($config_args);
90103

91104
if (isset($this->config['config']['standard'])) {
92-
$extra_config_options[] = '--standard=' . $this->config['config']['standard'];
105+
$runner->config->standards = explode(',', $this->config['config']['standard']);
93106
} else {
94-
$extra_config_options[] = '--standard=PSR1,PSR2';
95-
}
96-
97-
if (isset($this->config['config']['ignore_warnings']) && $this->config['config']['ignore_warnings']) {
98-
$extra_config_options[] = '-n';
107+
$runner->config->standards = array('PSR1', 'PSR2');
99108
}
100109

101110
if (isset($this->config['config']['encoding'])) {
102-
$extra_config_options[] = '--encoding=' . $this->config['config']['encoding'];
103-
}
104-
105-
foreach ($files as $file) {
106-
$extra_config_options[] = $file;
111+
$runner->config->encoding = $this->config['config']['encoding'];
107112
}
108113

109-
// prevent any stdout leakage
110-
ob_start();
111-
112-
// setup the code sniffer
113-
$runner = new \PHP_CodeSniffer\Runner();
114-
$runner->config = new Config($extra_config_options);
114+
$runner->config->reports = array( 'json' => null );
115+
$runner->config->reportFile = $resultFile;
115116
$runner->init();
116117

117-
// setup the code sniffer
118118
$runner->reporter = new Reporter($runner->config);
119119

120-
// start the code sniffing
121-
Timing::startTiming();
122-
$runner->checkRequirements();
123-
124-
$todo = new FileList($runner->config, $runner->ruleset);
125-
foreach ($todo as $path => $file) {
126-
if ($file->ignored === false) {
127-
$runner->processFile($file);
128-
}
120+
foreach ($files as $file_path) {
121+
$file = new DummyFile(file_get_contents($file_path), $runner->ruleset, $runner->config);
122+
$file->path = $file_path;
123+
124+
$runner->processFile($file);
129125
}
130126

131-
$runner->reporter->printReports();
127+
ob_start();
132128

133-
// clean up the output buffers (might be more that one)
134-
while (ob_get_level()) {
135-
ob_end_clean();
136-
}
129+
$runner->reporter->printReports();
130+
$report = ob_get_clean();
137131

138132
return $resultFile;
139133
} catch (\Throwable $e) {

circle.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
}
1717
},
1818
"require": {
19-
"squizlabs/php_codesniffer": "^3.5",
19+
"squizlabs/php_codesniffer": "^3.5.6",
2020
"barracudanetworks/forkdaemon-php": "^1.0",
2121
"danielstjules/stringy": "^2.3",
2222
"drupal/coder": "^8.3",
23-
"escapestudios/symfony2-coding-standard": "^3.9",
23+
"escapestudios/symfony2-coding-standard": "^3.10",
2424
"wp-coding-standards/wpcs": "^2.1",
2525
"yiisoft/yii2-coding-standards": "^2.0",
2626
"magento/marketplace-eqp": "^4.0",
27-
"magento/magento-coding-standard": "^4.0"
28-
"magento/marketplace-eqp": "^1.0",
27+
"magento/magento-coding-standard": "^4.0",
2928
"pheromone/phpcs-security-audit": "^1.0"
3029
}
3130
}

0 commit comments

Comments
 (0)