Skip to content

Commit d6017c4

Browse files
committed
Initial commit
0 parents  commit d6017c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4878
-0
lines changed

.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# OS
2+
.DS_Store
3+
Thumbs.db
4+
5+
# IDEs
6+
.buildpath
7+
.project
8+
.settings/
9+
.build/
10+
.external*/
11+
.idea/
12+
nbproject/
13+
14+
# symfony related
15+
var
16+
.env.local
17+
# composer related
18+
vendor/

.phpcq.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
phpcq:
2+
repositories:
3+
# Interim repository - change to real one when published.
4+
- ./web/repository.json
5+
directories:
6+
- src
7+
- tests
8+
artifact: .phpcq/build
9+
tools:
10+
phpcpd:
11+
version: ^5.0
12+
phpunit:
13+
version: ^9.0
14+
phploc:
15+
version: ^6.0
16+
17+
phpunit:
18+
custom_flags:
19+
20+
phpcpd:
21+
# exclude:
22+
# names:
23+
# names_exclude:
24+
# regexps_exclude:
25+
# log:
26+
# min_lines:
27+
# min_tokens:
28+
# fuzzy: true
29+
# custom_flags:
30+
31+
phploc:

.travis.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
dist: xenial
2+
3+
addons:
4+
apt:
5+
packages:
6+
- ant-optional
7+
8+
language: php
9+
10+
matrix:
11+
fast_finish: true
12+
include:
13+
# try to run against nightly - will fail until we support php 8
14+
# - php: nightly
15+
# minimum requirement test
16+
- php: 7.4
17+
env:
18+
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
19+
# latest requirement test
20+
- php: 7.4
21+
env:
22+
- COMPOSER_FLAGS=""
23+
# allow_failures:
24+
# - php: nightly
25+
26+
before_install:
27+
- echo "memory_limit = -1" > travis.php.ini && phpenv config-add travis.php.ini
28+
29+
install:
30+
- travis_retry composer self-update && composer --version
31+
- >
32+
if [ "x${TRAVIS_TAG}" != "x" ]; then
33+
COMPOSER_ROOT_VERSION=${TRAVIS_TAG} travis_retry composer update --prefer-dist --no-interaction;
34+
else
35+
COMPOSER_ROOT_VERSION=$([[ ${TRAVIS_BRANCH} =~ (release|hotfix)/([0-9.]*(-(alpha|beta|rc)[0-9]+)?) ]] \
36+
&& echo ${BASH_REMATCH[2]} \
37+
|| echo dev-${TRAVIS_BRANCH}) \
38+
travis_retry composer update $COMPOSER_FLAGS --prefer-dist --no-interaction;
39+
fi
40+
- ./phpcq update
41+
42+
script:
43+
- ./phpcq run
44+
45+
# Hack to make things work again - we can not use a shallow repository.
46+
git:
47+
depth: 2147483647
48+
49+
cache:
50+
directories:
51+
- vendor

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2014-2020 Christian Schiffler, David Molineus
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

bin/console

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
use Phpcq\RepositoryBuilder\Kernel;
7+
use Symfony\Bundle\FrameworkBundle\Console\Application;
8+
use Symfony\Component\Console\Input\ArgvInput;
9+
use Symfony\Component\Debug\Debug;
10+
11+
if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
12+
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
13+
}
14+
15+
set_time_limit(0);
16+
17+
require dirname(__DIR__).'/vendor/autoload.php';
18+
19+
if (!class_exists(Application::class)) {
20+
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
21+
}
22+
23+
$input = new ArgvInput();
24+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
25+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
26+
}
27+
28+
if ($input->hasParameterOption('--no-debug', true)) {
29+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
30+
}
31+
32+
require dirname(__DIR__).'/config/bootstrap.php';
33+
34+
if ($_SERVER['APP_DEBUG']) {
35+
umask(0000);
36+
37+
if (class_exists(Debug::class)) {
38+
Debug::enable();
39+
}
40+
}
41+
42+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
43+
$application = new Application($kernel);
44+
$application->run($input);

bootstrap/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Bootstrap library.
2+
3+
Each tool bootstrap ends up in here.

bootstrap/catalog.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"phpcpd": [
3+
{
4+
"constraint": "*",
5+
"file": "phpcpd/phpcpd-all.php",
6+
"plugin-version": "1.0.0"
7+
}
8+
],
9+
"phploc": [
10+
{
11+
"constraint": "*",
12+
"file": "phploc/phploc-all.php",
13+
"plugin-version": "1.0.0"
14+
}
15+
],
16+
"phpmd": [
17+
{
18+
"constraint": "*",
19+
"file": "phpmd/phpmd-all.php",
20+
"plugin-version": "1.0.0"
21+
}
22+
],
23+
"phpunit": [
24+
{
25+
"constraint": "*",
26+
"file": "phpunit/phpunit-all.php",
27+
"plugin-version": "1.0.0"
28+
}
29+
]
30+
}

bootstrap/phpcpd/phpcpd-all.php

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
use Phpcq\Config\BuildConfigInterface;
4+
use Phpcq\Plugin\ConfigurationPluginInterface;
5+
6+
/**
7+
* Tool home: https://github.com/sebastianbergmann/phpcpd
8+
*/
9+
return new class implements ConfigurationPluginInterface {
10+
public function getName() : string
11+
{
12+
return 'phpcpd';
13+
}
14+
15+
/**
16+
* exclude [array] Exclude directories from code analysis (must be relative to source).
17+
* names [array] A list of file names to check [default: ["*.php"]].
18+
* names_exclude [array] A list of file names to exclude.
19+
* regexps_exclude [array] A list of paths regexps to exclude (example: "#var/.*_tmp#")
20+
* log [string] Write result in PMD-CPD XML format to file.
21+
* min_lines [int] Minimum number of identical lines [default: 5]
22+
* min_tokens [int] Minimum number of identical tokens [default: 70]
23+
* fuzzy [bool] Fuzz variable names
24+
*
25+
* custom_flags [string] Any custom flags to pass to phpcpd. For valid flags refer to the phpcpd documentation.
26+
*
27+
* directories [array] source directories to be analyzed with phpcpd.
28+
*
29+
* @var string[]
30+
*/
31+
private static $knownConfigKeys = [
32+
'exclude' => 'exclude',
33+
'names' => 'names',
34+
'names_exclude' => 'names_exclude',
35+
'regexps_exclude' => 'regexps_exclude',
36+
'log' => 'log',
37+
'min_lines' => 'min_lines',
38+
'min_tokens' => 'min_tokens',
39+
'fuzzy' => 'fuzzy',
40+
'custom_flags' => 'custom_flags',
41+
'directories' => 'directories',
42+
];
43+
44+
public function validateConfig(array $config) : void
45+
{
46+
if ($diff = array_diff_key($config, self::$knownConfigKeys)) {
47+
throw new \Phpcq\Exception\RuntimeException(
48+
'Unknown config keys encountered: ' . implode(', ', array_keys($diff))
49+
);
50+
}
51+
}
52+
53+
public function processConfig(array $config, BuildConfigInterface $buildConfig) : iterable
54+
{
55+
$args = [];
56+
if ([] !== ($excluded = (array) ($config['exclude'] ?? []))) {
57+
foreach ($excluded as $path) {
58+
if ('' === ($path = trim($path))) {
59+
continue;
60+
}
61+
$args[] = '--exclude=' . $path;
62+
63+
}
64+
}
65+
if ('' !== ($values = $this->commaValues($config, 'names'))) {
66+
$args[] = '--names=' . $values;
67+
}
68+
if ('' !== ($values = $this->commaValues($config, 'names_exclude'))) {
69+
$args[] = '--names-exclude=' . $values;
70+
}
71+
if ('' !== ($values = $this->commaValues($config, 'regexps_exclude'))) {
72+
$args[] = '--regexps-exclude=' . $values;
73+
}
74+
if ('' !== ($values = $config['log'] ?? '')) {
75+
$args[] = '--log-pmd=' . $values;
76+
}
77+
if ('' !== ($values = $config['min_lines'] ?? '')) {
78+
$args[] = '--min-lines=' . $values;
79+
}
80+
if ('' !== ($values = $config['min_tokens'] ?? '')) {
81+
$args[] = '--min-tokens=' . $values;
82+
}
83+
if ($config['fuzzy'] ?? false) {
84+
$args[] = '--fuzzy';
85+
}
86+
if ('' !== ($values = $config['custom_flags'] ?? '')) {
87+
$args[] = 'custom_flags';
88+
}
89+
90+
yield $buildConfig
91+
->getTaskFactory()
92+
->buildRunPhar('phpcpd', array_merge($args, $config['directories']))
93+
->withWorkingDirectory($buildConfig->getProjectConfiguration()->getProjectRootPath())
94+
->build();
95+
}
96+
97+
private function commaValues(array $config, string $key): string
98+
{
99+
if (!isset($config[$key])) {
100+
return '';
101+
}
102+
return implode(',', (array) $config[$key]);
103+
}
104+
};

bootstrap/phploc/phploc-all.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
use Phpcq\Config\BuildConfigInterface;
4+
use Phpcq\Plugin\ConfigurationPluginInterface;
5+
6+
/**
7+
* Tool home: https://github.com/sebastianbergmann/phploc
8+
*/
9+
return new class implements ConfigurationPluginInterface {
10+
public function getName() : string
11+
{
12+
return 'phploc';
13+
}
14+
15+
/**
16+
* exclude [array] List of excluded files and folders.
17+
* output [array] List of outputs to use.
18+
*
19+
* custom_flags [string] Any custom flags to pass to phploc. For valid flags refer to the phploc documentation.
20+
*
21+
* directories [array] source directories to be analyzed with phploc.
22+
*
23+
* @var string[]
24+
*/
25+
private static $knownConfigKeys = [
26+
'exclude' => 'exclude',
27+
'output' => 'output',
28+
'custom_flags' => 'custom_flags',
29+
'directories' => 'directories',
30+
];
31+
32+
public function validateConfig(array $config) : void
33+
{
34+
if ($diff = array_diff_key($config, self::$knownConfigKeys)) {
35+
throw new \Phpcq\Exception\RuntimeException(
36+
'Unknown config keys encountered: ' . implode(', ', array_keys($diff))
37+
);
38+
}
39+
}
40+
41+
public function processConfig(array $config, BuildConfigInterface $buildConfig) : iterable
42+
{
43+
$args = [];
44+
if ([] !== ($excluded = (array) ($config['exclude'] ?? []))) {
45+
foreach ($excluded as $path) {
46+
if ('' === ($path = trim($path))) {
47+
continue;
48+
}
49+
$args[] = '--exclude=' . $path;
50+
51+
}
52+
}
53+
if ('' !== ($values = $config['custom_flags'] ?? '')) {
54+
$args[] = 'custom_flags';
55+
}
56+
57+
yield $buildConfig
58+
->getTaskFactory()
59+
->buildRunPhar('phploc', array_merge($args, $config['directories']))
60+
->withWorkingDirectory($buildConfig->getProjectConfiguration()->getProjectRootPath())
61+
->build();
62+
}
63+
64+
private function commaValues(array $config, string $key): string
65+
{
66+
if (!isset($config[$key])) {
67+
return '';
68+
}
69+
return implode(',', (array) $config[$key]);
70+
}
71+
};

0 commit comments

Comments
 (0)