Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@

## Интеграция с pull request
Добавить webhook в atlassian stash с указанием ссылки на index.php из phpcs-bitbucket с аргументами index.php?branch=${refChange.refId}&repo=${project.key}&slug=${repository.slug}

#Конфигурация

Блок [phpvardumpcheck] поддерживает:

```
className='PhpCsBitBucket\Checker\PhpVarDumpCheck' ;Class to check
mode='--symfony' ; mode (more - https://github.com/JakubOnderka/PHP-Var-Dump-Check#options-for-run)
skipFunctions='var_export' ; functions, that will be skiped
```
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "whotrades/bitbucket-code-style",
"type": "library",
"author": "Artem Naumenko",
"authors": [
{
"name": "Artem Naumenko",
"role": "Developer"
}
],
"description": "Robot for integration code style checking at atlassian bitbucket (supports phpcs and cpplint)",
"autoload": {
"psr-4": {
Expand All @@ -13,6 +18,7 @@
"squizlabs/php_codesniffer": "3.*",
"guzzlehttp/guzzle": "~6.3",
"monolog/monolog": "~1.23",
"php": ">=7.0"
"php": ">=7.0",
"jakub-onderka/php-var-dump-check": "^0.3.0"
}
}
50 changes: 48 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion configuration.ini-dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ httpTimeout = 90

[checkers]
; coma separated list of checkers
list=phpcs
list=phpcs,phpvardumpcheck

[phpcs]
className=PhpCsBitBucket\Checker\PhpCs
Expand All @@ -23,6 +23,10 @@ standard='vendor/squizlabs/php_codesniffer/src/Standards/PSR2/ruleset.xml'
; Пути установки дополнительных стилей кодирования
installed_paths=''

[phpvardumpcheck]
className='PhpCsBitBucket\Checker\PhpVarDumpCheck'
mode='--symfony'

[cpp]
className=PhpCsBitBucket\Checker\Cpp
; Путь к cpplint
Expand Down
117 changes: 117 additions & 0 deletions lib/Checker/PhpVarDumpCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
*
* @author Danil Pyatnitsev <danil@pyatnitsev.ru>
*
* @copyright © 2011-2019 WhoTrades, Ltd. (http://whotrades.com). All rights reserved.
*/

namespace PhpCsBitBucket\Checker;

use Monolog\Logger;
use PhpCsBitBucket\CheckerResult\CheckerResultItem;
use PhpCsBitBucket\CheckerResult\CheckerResultItemInterface;

class PhpVarDumpCheck implements CheckerInterface
{
/**
* @var Logger
*/
private $log;

/**
* @var array
*/
private $config;

/**
* @var string
*/
private $tmpDir;

/**
* @param Logger $log
* @param array $config
*/
public function __construct(Logger $log, array $config)
{
$this->log = $log;
$this->config = $config;
$this->tmpDir = $config['tmpdir'] ?? '/tmp';
}

/**
* @param string $filename
* @param string $extension
*
* @return bool
*/
public function shouldIgnoreFile($filename, $extension)
{
if (!empty($this->config['extensions'])) {
$checkOnly = explode(',', $this->config['extensions']);

return !in_array($extension, $checkOnly);
}

return false;
}

/**
* @param string $filePath
*
* @return \JakubOnderka\PhpVarDumpCheck\Settings
*
* @throws \JakubOnderka\PhpVarDumpCheck\Exception\InvalidArgument
*/
private function getToolConfig(string $filePath)
{
$config = [0];
if (isset($this->config['mode'])) {
$config[] = $this->config['mode'];
}

$settings = \JakubOnderka\PhpVarDumpCheck\Settings::parseArguments(array_merge($config, [$filePath]));

if (isset($this->config['skipFunctions'])) {
$skipFunctions = explode(',', $this->config['skipFunctions']);
foreach ($skipFunctions as $function) {
if (($key = array_search($function, $settings->functionsToCheck)) !== false) {
unset($settings->functionsToCheck[$key]);
}
}
}

return $settings;
}

/**
* @param string $filename
* @param string $extension
* @param string $fileContent
*
* @return CheckerResultItemInterface[]
*
* @throws \JakubOnderka\PhpVarDumpCheck\Exception\InvalidArgument
*/
public function processFile($filename, $extension, $fileContent)
{
// prepare an temp file for catch
$tempFile = "$this->tmpDir/temp.$extension";
file_put_contents($tempFile, $fileContent);
$result = [];
try {
$check = new \JakubOnderka\PhpVarDumpCheck\Manager();
$status = $check->checkFile($tempFile, $this->getToolConfig($tempFile));
foreach ($status as $item) {
$result[] = new CheckerResultItem($item->getLineNumber(), 'Forgotten dump found');
}
} catch (\Exception $e) {
$this->log->addCritical($e->getMessage(), $e->getTrace());
}

unlink($tempFile);

return $result;
}
}