-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathPhpLoc.php
More file actions
82 lines (68 loc) · 2.05 KB
/
Copy pathPhpLoc.php
File metadata and controls
82 lines (68 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace PHPCensor\Plugin;
use PHPCensor;
use PHPCensor\Builder;
use PHPCensor\Model\Build;
use PHPCensor\Model\User;
use PHPCensor\Plugin;
use PHPCensor\ZeroConfigPluginInterface;
/**
* PHP Loc - Allows PHP Copy / Lines of Code testing.
*
* @package PHP Censor
* @subpackage Application
*
* @author Johan van der Heide <info@japaveh.nl>
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class PhpLoc extends Plugin implements ZeroConfigPluginInterface
{
/**
* @return string
*/
public static function pluginName()
{
return 'php_loc';
}
/**
* {@inheritDoc}
*/
public static function canExecuteOnStage($stage, Build $build)
{
if (Build::STAGE_TEST === $stage) {
return true;
}
return false;
}
/**
* {@inheritDoc}
*/
public function __construct(Builder $builder, Build $build, array $options = [])
{
parent::__construct($builder, $build, $options);
$this->executable = $this->findBinary(['phploc', 'phploc.phar']);
}
/**
* Runs PHP LOC in a specified directory.
*/
public function execute()
{
$ignore = '';
if (\is_array($this->ignore)) {
$map = fn ($item) => \sprintf(' --exclude="%s"', $item);
$ignore = \array_map($map, $this->ignore);
$ignore = \implode('', $ignore);
}
$phploc = $this->executable;
$success = $this->builder->executeCommand('cd "%s" && ' . Builder::PHP_CLI_TAG . ' -d xdebug.mode=off -d error_reporting=0 ' . Builder::PHP_CLI_TAG . ' ' . $phploc . ' %s %s', $this->builder->buildPath, $ignore, $this->directory);
$output = $this->builder->getLastOutput();
if (\preg_match_all('/\((LOC|CLOC|NCLOC|LLOC)\)\s+([0-9]+)/', $output, $matches)) {
$data = [];
foreach ($matches[1] as $k => $v) {
$data[$v] = (int)$matches[2][$k];
}
$this->build->storeMeta((self::pluginName() . '-data'), $data);
}
return $success;
}
}