Skip to content

Commit 54606b9

Browse files
committed
feat(CLI): Push initial commit
1 parent 94f15cb commit 54606b9

Some content is hidden

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

43 files changed

+12431
-8
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/anibal/7_Projects/Platform/extly-coding-standards/editorconfig.psr2

.env

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
APP_NAME="My Application"
2+
3+
SOURCE_DIRECTORY="/home/anibal/7_Projects/PHP-Prefixer/php-prefixer-rest-api-cli/tests/Mock/Source"
4+
TARGET_DIRECTORY="/home/anibal/7_Projects/PHP-Prefixer/php-prefixer-rest-api-cli/tests/Mock/Target"
5+
PERSONAL_ACCESS_TOKEN="..."
6+
PROJECT_ID="..."
7+
GITHUB_ACCESS_TOKEN="..."
8+
9+
# Only for testing
10+
INVALID_PERSONAL_ACCESS_TOKEN="..."
11+
INVALID_GITHUB_ACCESS_TOKEN="..."

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
* text=auto
2+
/.github export-ignore
3+
.styleci.yml export-ignore
4+
.scrutinizer.yml export-ignore
5+
BACKERS.md export-ignore
6+
CONTRIBUTING.md export-ignore
7+
CHANGELOG.md export-ignore

.gitignore

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
composer.phar
2-
/vendor/
3-
4-
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
2+
/vendor
3+
/tests/Mock/Source/vendor
4+
/.idea
5+
/.vscode
6+
/.vagrant
7+
.phpunit.result.cache
8+
.phan
9+
/builds

.markdownlint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/anibal/7_Projects/Platform/extly-coding-standards/markdownlint.json

.php_cs.dist

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
$header = <<<'EOF'
4+
@package PHP Prefixer REST API CLI
5+
6+
@author Desarrollos Inteligentes Virtuales, SL. <team@div.com.es>
7+
@copyright Copyright (c)2019-2021 Desarrollos Inteligentes Virtuales, SL. All rights reserved.
8+
@license MIT
9+
10+
@see https://php-prefixer.com
11+
EOF;
12+
13+
$finder = PhpCsFixer\Finder::create()
14+
->exclude('tests/Fixtures')
15+
->in(__DIR__)
16+
;
17+
18+
$config = PhpCsFixer\Config::create()
19+
->setRiskyAllowed(true)
20+
->setRules([
21+
'@PHP56Migration' => true,
22+
'@PHPUnit60Migration:risky' => true,
23+
'@Symfony' => true,
24+
'@Symfony:risky' => true,
25+
'align_multiline_comment' => true,
26+
'array_indentation' => true,
27+
'array_syntax' => ['syntax' => 'short'],
28+
'blank_line_before_statement' => true,
29+
'combine_consecutive_issets' => true,
30+
'combine_consecutive_unsets' => true,
31+
'comment_to_phpdoc' => true,
32+
'compact_nullable_typehint' => true,
33+
'escape_implicit_backslashes' => true,
34+
'explicit_indirect_variable' => true,
35+
'explicit_string_variable' => true,
36+
'final_internal_class' => true,
37+
'fully_qualified_strict_types' => true,
38+
'function_to_constant' => ['functions' => ['get_class', 'get_called_class', 'php_sapi_name', 'phpversion', 'pi']],
39+
'header_comment' => ['header' => $header],
40+
'heredoc_to_nowdoc' => true,
41+
'list_syntax' => ['syntax' => 'long'],
42+
'method_argument_space' => ['ensure_fully_multiline' => true],
43+
'method_chaining_indentation' => true,
44+
'multiline_comment_opening_closing' => true,
45+
'no_alternative_syntax' => true,
46+
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
47+
'no_null_property_initialization' => true,
48+
'no_short_echo_tag' => true,
49+
'no_superfluous_elseif' => true,
50+
'no_unneeded_curly_braces' => true,
51+
'no_unneeded_final_method' => true,
52+
'no_unreachable_default_argument_value' => true,
53+
'no_useless_else' => true,
54+
'no_useless_return' => true,
55+
'ordered_class_elements' => true,
56+
'ordered_imports' => true,
57+
'php_unit_ordered_covers' => true,
58+
'php_unit_set_up_tear_down_visibility' => true,
59+
'php_unit_strict' => true,
60+
'php_unit_test_annotation' => true,
61+
'php_unit_test_class_requires_covers' => true,
62+
'phpdoc_add_missing_param_annotation' => true,
63+
'phpdoc_order' => true,
64+
'phpdoc_types_order' => true,
65+
'semicolon_after_instruction' => true,
66+
'single_line_comment_style' => true,
67+
'strict_comparison' => true,
68+
'strict_param' => true,
69+
'string_line_ending' => true,
70+
'yoda_style' => true,
71+
])
72+
->setFinder($finder)
73+
;
74+
75+
// special handling of fabbot.io service if it's using too old PHP CS Fixer version
76+
if (false !== getenv('FABBOT_IO')) {
77+
try {
78+
PhpCsFixer\FixerFactory::create()
79+
->registerBuiltInFixers()
80+
->registerCustomFixers($config->getCustomFixers())
81+
->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()));
82+
} catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
83+
$config->setRules([]);
84+
} catch (UnexpectedValueException $e) {
85+
$config->setRules([]);
86+
} catch (InvalidArgumentException $e) {
87+
$config->setRules([]);
88+
}
89+
}
90+
91+
return $config;

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
We accept contributions via Pull Requests on [Github](https://github.com/php-prefixer/php-prefixer-rest-api-cli).
6+
7+
## Pull Requests
8+
9+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
10+
11+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
12+
13+
- **Consider our release cycle** - We follow Sematic versioning scheme. We follow the convention `paradigm.major.minor`. Minor releases should never contain breaking changes.
14+
15+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
16+
17+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
18+
19+
20+
## Running Tests
21+
22+
``` bash
23+
$ ./vendor/bin/pest
24+
```
25+
26+
**Happy coding**!

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 PHP-Prefixer
3+
Copyright (c) 2019-2021 PHP-Prefixer, Desarrollos Inteligentes Virtuales, SL.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,77 @@
1-
# php-prefixer-rest-client
2-
A REST client for the PHP-Prefixer service.
1+
# PHP Prefixer REST API CLI
2+
3+
![PHP-Prefixer](https://php-prefixer.com/images/logo/php-prefixer-144x144.png)
4+
5+
A REST client for the PHP-Prefixer service.
6+
7+
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSEs)
8+
9+
## Run Locally
10+
11+
Clone the project
12+
13+
```bash
14+
git clone https://github.com/php-prefixer/php-prefixer-rest-api-cli
15+
```
16+
17+
Go to the project directory
18+
19+
```bash
20+
cd php-prefixer-rest-api-cli
21+
```
22+
23+
Install dependencies
24+
25+
```bash
26+
composer update
27+
```
28+
29+
Run the prefixer service
30+
31+
```bash
32+
./php-prefixer-rest-api-cli prefix ./tests/Mock/Source ./tests/Mock/Target \
33+
$PHP_PREFIXER_PERSONAL_ACCESS_TOKEN \
34+
aaa \
35+
--github-access-token=$PHP_PREFIXER_GH_TOKEN
36+
```
37+
38+
## Environment Variables
39+
40+
To run this project, you will need to add the following environment variables to your .env file
41+
42+
`API_KEY`
43+
44+
`ANOTHER_API_KEY`
45+
46+
47+
## Documentation
48+
49+
- [PHP-Prefixer Documentation](https://php-prefixer.com/docs)
50+
- [REST API Referece](https://php-prefixer.com/docs/api-documentation/)
51+
52+
## Running Tests
53+
54+
To run tests, run the following command
55+
56+
```bash
57+
phpunit
58+
```
59+
60+
## Contributing
61+
62+
Contributions are always welcome!
63+
64+
See `contributing.md` for ways to get started.
65+
66+
## Security
67+
68+
If you discover a security vulnerability within this package, please send an email to Graham Campbell at team@php-prefixer.com. All security vulnerabilities will be promptly addressed.
69+
70+
## License
71+
72+
[MIT](https://choosealicense.com/licenses/mit/)
73+
74+
## Authors
75+
76+
- [Aníbal Sánchez](https://www.twitter.com/anibal_sanchez)
77+
- [PHP-Prefixer](https://php-prefixer.com/), Desarrollos Inteligentes Virtuales, SL.

app/Commands/PrefixCommand.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
/*
4+
* @package PHP Prefixer REST API CLI
5+
*
6+
* @author Desarrollos Inteligentes Virtuales, SL. <team@div.com.es>
7+
* @copyright Copyright (c)2019-2021 Desarrollos Inteligentes Virtuales, SL. All rights reserved.
8+
* @license MIT
9+
*
10+
* @see https://php-prefixer.com
11+
*/
12+
13+
namespace App\Commands;
14+
15+
use App\Support\Processor;
16+
use App\Support\Validator;
17+
use Illuminate\Support\Str;
18+
use LaravelZero\Framework\Commands\Command;
19+
20+
class PrefixCommand extends Command
21+
{
22+
/**
23+
* The signature of the command.
24+
*
25+
* @var string
26+
*/
27+
protected $signature = 'prefix
28+
{source-directory : Project source directory}
29+
{target-directory : Project target directory}
30+
{personal-access-token : Personal Access Token generates on https://php-prefixer.com}
31+
{project-id : The project ID to process the source code}
32+
{--github-access-token= : Github access token for private repositories}
33+
';
34+
35+
/**
36+
* The description of the command.
37+
*
38+
* @var string
39+
*/
40+
protected $description = 'Prefix a PHP project';
41+
42+
/**
43+
* Execute the console command.
44+
*
45+
* @return mixed
46+
*/
47+
public function handle()
48+
{
49+
$appName = config('app.name');
50+
$invalidPersonalAccessToken = env('INVALID_PERSONAL_ACCESS_TOKEN');
51+
52+
$validator = new Validator();
53+
$sourceDirectory = $this->argumentOrEnv('source-directory');
54+
55+
if (!$sourcePath = $validator->validateDirectoryExists($sourceDirectory)) {
56+
$this->error("{$sourceDirectory} not found");
57+
58+
return 1;
59+
}
60+
61+
$targetPath = $this->argumentOrEnv('target-directory');
62+
63+
if (!$sourcePath = $validator->validateDirectoryEmpty($sourceDirectory)) {
64+
$this->error("{$sourceDirectory} not found");
65+
66+
return 1;
67+
}
68+
69+
if (!$personalAccessToken = $validator->validatePAT($this->argumentOrEnv('personal-access-token'))) {
70+
$this->error(
71+
'The Personal Access Token is invalid. Please, generate a new token on https://php-prefixer.com.'
72+
);
73+
74+
return 1;
75+
}
76+
77+
if (!$projectId = $validator->validateProject($personalAccessToken, $this->argumentOrEnv('project-id'))) {
78+
$this->error(
79+
'The Project ID is invalid'
80+
);
81+
82+
return 1;
83+
}
84+
85+
$githubAccessToken = $this->optionOrEnv('github-access-token');
86+
87+
if ($githubAccessToken && !$validator->validateGAT($githubAccessToken)) {
88+
$this->error(
89+
'The Github Access Token is invalid'
90+
);
91+
92+
return 1;
93+
}
94+
95+
$processor = new Processor($personalAccessToken);
96+
$processor->run($sourcePath, $targetPath, $projectId, $githubAccessToken);
97+
98+
$this->info('Project prefixed successfully');
99+
100+
return 0;
101+
}
102+
103+
private function argumentOrEnv($key)
104+
{
105+
if ($value = $this->argument($key)) {
106+
return $value;
107+
}
108+
109+
return env($key);
110+
}
111+
112+
private function optionOrEnv($key)
113+
{
114+
if ($value = $this->option($key)) {
115+
return $value;
116+
}
117+
118+
return env(Str::upper(Str::snake($key)));
119+
}
120+
}

0 commit comments

Comments
 (0)