Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update PHP Codesniffer#82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
f-moya wants to merge3 commits intocodeclimate:masterfromf-moya:master
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions.circleci/config.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
version: 2.1

jobs:
build:
machine:
docker_layer_caching: true
working_directory: ~/codeclimate/codeclimate-phpcodesniffer
steps:
- checkout
- run:
name: Build
command: make image
notify:
webhooks:
- url: https://cc-slack-proxy.herokuapp.com/circle
12 changes: 3 additions & 9 deletionsDockerfile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
FROM alpine:edge
FROM alpine:3.12

RUN adduser -u 9000 -D app

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

COPY --from=composer /usr/bin/composer /usr/local/bin/composer
COPY composer.json composer.lock ./

RUN apk add --no-cache git && \
Expand Down
140 changes: 140 additions & 0 deletionsExecutor.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
<?php

use Stringy\Stringy as S;
use PHP_CodeSniffer\Runner;
use PHP_CodeSniffer\Config;
use PHP_CodeSniffer\Reporter;
use PHP_CodeSniffer\Files\DummyFile;
use PHP_CodeSniffer\Util\Timing;

require_once __DIR__.'/vendor/squizlabs/php_codesniffer/autoload.php';

class Executor
{
const DEFAULT_EXTENSIONS = array("php", "inc", "module");

private $config;
private $server;

public function __construct($config, $server)
{
$this->config = $config;
$this->server = $server;
}

public function queueDirectory($dir, $prefix = '')
{
chdir("/code");

if (isset($this->config['include_paths'])) {
$this->queueWithIncludePaths();
} else {
$this->queuePaths($dir, $prefix, $this->config['exclude_paths']);
}

$this->server->process_work(false);
}

public function queueWithIncludePaths()
{
foreach ($this->config['include_paths'] as $f) {
if ($f !== '.' and $f !== '..') {
if (is_dir($f)) {
$this->queuePaths("$f", "$f/");
} else {
$this->filterByExtension($f);
}
}
}
}

public function queuePaths($dir, $prefix = '', $exclusions = [])
{
$dir = rtrim($dir, '\\/');

foreach (scandir($dir) as $f) {
if (in_array("$prefix$f", $exclusions)) {
continue;
}

if ($f !== '.' and $f !== '..') {
if (is_dir("$dir/$f")) {
$this->queuePaths("$dir/$f", "$prefix$f/", $exclusions);
} else {
$this->filterByExtension($f, $prefix);
}
}
}
}

public function filterByExtension($f, $prefix = '')
{
foreach ($this->fileExtensions() as $file_extension) {
if (S::create($f)->endsWith($file_extension)) {
$prefix = ltrim($prefix, "\\/");
$this->server->addwork(array("$prefix$f"));
}
}
}

private function fileExtensions()
{
$extensions = $this->config['config']['file_extensions'];

if (empty($extensions)) {
return self::DEFAULT_EXTENSIONS;
} else {
return explode(",", $extensions);
}
}

public function run($files)
{
try {
$resultFile = tempnam(sys_get_temp_dir(), 'phpcodesniffer');
$config_args = array( '-s', '-p' );

if (isset($this->config['config']['ignore_warnings']) && $this->config['config']['ignore_warnings']) {
$config_args[] = '-n';
}

Timing::startTiming();

$runner = new Runner();
$runner->config = new Config($config_args);

if (isset($this->config['config']['standard'])) {
$runner->config->standards = explode(',', $this->config['config']['standard']);
} else {
$runner->config->standards = array('PSR1', 'PSR2');
}

if (isset($this->config['config']['encoding'])) {
$runner->config->encoding = $this->config['config']['encoding'];
}

$runner->config->reports = array( 'json' => null );
$runner->config->reportFile = $resultFile;
$runner->init();

$runner->reporter = new Reporter($runner->config);

foreach ($files as $file_path) {
$file = new DummyFile(file_get_contents($file_path), $runner->ruleset, $runner->config);
$file->path = $file_path;

$runner->processFile($file);
}

ob_start();

$runner->reporter->printReports();
$report = ob_get_clean();

return $resultFile;
} catch (\Throwable $e) {
error_log("Exception: " . $e->getMessage() . " in " . $e->getFile() . "\n" . $e->getTraceAsString());
return $e;
}
}
}
4 changes: 2 additions & 2 deletionscomposer.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,11 +16,11 @@
}
},
"require": {
"squizlabs/php_codesniffer": "^2.9.1",
"squizlabs/php_codesniffer": "^3.5.6",
"barracudanetworks/forkdaemon-php": "^1.0",
"danielstjules/stringy": "^2.3",
"drupal/coder": "^8.2",
"escapestudios/symfony2-coding-standard": "^2.10",
"escapestudios/symfony2-coding-standard": "^3.10",
"wp-coding-standards/wpcs": "^1.0.0",
"yiisoft/yii2-coding-standards": "^2.0",
"magento/marketplace-eqp": "^1.0"
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp