-
Notifications
You must be signed in to change notification settings - Fork 2
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement: Add PHP-CS-Fixer #31
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
vendor/ | ||
composer.lock | ||
.php_cs.cache | ||
.php-cs-fixer.cache | ||
.php-cs-fixer.dist.php | ||
.idea/ | ||
.build | ||
.php-version |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of the Pushover package. | ||
* | ||
* (c) Serhiy Lunak <https://github.com/slunak> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Ergebnis\PhpCsFixer\Config\Factory; | ||
use Ergebnis\PhpCsFixer\Config\Rules; | ||
use Ergebnis\PhpCsFixer\Config\RuleSet\Php74; | ||
|
||
$header = <<<'HEADER' | ||
This file is part of the Pushover package. | ||
|
||
(c) Serhiy Lunak <https://github.com/slunak> | ||
|
||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
HEADER; | ||
|
||
$ruleSet = Php74::create()->withHeader($header)->withRules(Rules::fromArray([ | ||
'blank_line_before_statement' => [ | ||
'statements' => [ | ||
'break', | ||
'continue', | ||
'declare', | ||
'default', | ||
'do', | ||
'exit', | ||
'for', | ||
'foreach', | ||
'goto', | ||
'if', | ||
'include', | ||
'include_once', | ||
'require', | ||
'require_once', | ||
'return', | ||
'switch', | ||
'throw', | ||
'try', | ||
'while', | ||
], | ||
], | ||
'concat_space' => [ | ||
'spacing' => 'none', | ||
], | ||
'date_time_immutable' => false, | ||
'error_suppression' => false, | ||
'final_class' => false, | ||
'mb_str_functions' => false, | ||
'native_function_invocation' => [ | ||
'exclude' => [ | ||
'sprintf', | ||
], | ||
'include' => [ | ||
'@compiler_optimized', | ||
], | ||
'scope' => 'all', | ||
'strict' => false, | ||
], | ||
'php_unit_internal_class' => false, | ||
'php_unit_test_annotation' => [ | ||
'style' => 'prefix', | ||
], | ||
'php_unit_test_class_requires_covers' => false, | ||
'return_to_yield_from' => false, | ||
'phpdoc_array_type' => false, | ||
'phpdoc_list_type' => false, | ||
'attribute_empty_parentheses' => false, | ||
'final_public_method_for_abstract_class' => false, | ||
'class_attributes_separation' => [ | ||
'elements' => [ | ||
'const' => 'only_if_meta', | ||
'property' => 'only_if_meta', | ||
'trait_import' => 'none', | ||
'case' => 'none', | ||
], | ||
], | ||
|
||
// temp disabled to keep the diff small in the first run | ||
'declare_strict_types' => false, | ||
'void_return' => false, | ||
'ordered_imports' => false, | ||
'php_unit_test_case_static_method_calls' => false, | ||
'strict_comparison' => false, | ||
'yoda_style' => false, | ||
'phpdoc_to_property_type' => false, | ||
'phpdoc_summary' => false, | ||
'nullable_type_declaration_for_default_null_value' => false, | ||
Comment on lines
+88
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will activate and execute them, once this PR is merged. |
||
])); | ||
|
||
$config = Factory::fromRuleSet($ruleSet); | ||
|
||
$config->getFinder() | ||
->append([ | ||
__DIR__.'/.php-cs-fixer.dist.php', | ||
]) | ||
->in('src') | ||
->in('tests'); | ||
|
||
$config->setCacheFile(__DIR__.'/.build/php-cs-fixer/.php-cs-fixer.cache'); | ||
|
||
return $config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# vim: set tabstop=8 softtabstop=8 noexpandtab: | ||
.PHONY: help | ||
help: ## Displays this list of targets with descriptions | ||
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
.PHONY: cs | ||
cs: vendor ## Normalizes composer.json with ergebnis/composer-normalize and fixes code style issues with friendsofphp/php-cs-fixer | ||
symfony composer normalize | ||
mkdir -p .build/php-cs-fixer | ||
symfony php vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --diff --verbose |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also executes "composer normalize" |
||
"name": "serhiy/pushover", | ||
"description": "Light, simple and fast, yet comprehensive wrapper for the Pushover API.", | ||
"type": "library", | ||
"keywords": ["pushover", "pushover.net", "wrapper", "client"], | ||
"homepage": "https://github.com/slunak/pushover-php", | ||
"require": { | ||
"php": ">=7.4", | ||
"ext-curl": "*", | ||
"ext-json": "*" | ||
}, | ||
"license": "MIT", | ||
"type": "library", | ||
"keywords": [ | ||
"pushover", | ||
"pushover.net", | ||
"wrapper", | ||
"client" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Serhiy Lunak", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
"role": "Developer" | ||
} | ||
], | ||
"homepage": "https://github.com/slunak/pushover-php", | ||
"require": { | ||
"php": ">=7.4", | ||
"ext-curl": "*", | ||
"ext-json": "*" | ||
}, | ||
"require-dev": { | ||
"ergebnis/php-cs-fixer-config": "^6.34", | ||
"friendsofphp/php-cs-fixer": "^3.61", | ||
"phpunit/phpunit": "*", | ||
"ergebnis/composer-normalize": "^2.43" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Serhiy\\Pushover\\": "src/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "*" | ||
"config": { | ||
"allow-plugins": { | ||
"ergebnis/composer-normalize": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
/* | ||
/** | ||
* This file is part of the Pushover package. | ||
* | ||
* (c) Serhiy Lunak <https://github.com/slunak> | ||
|
@@ -32,17 +32,17 @@ | |
class Glance | ||
{ | ||
/** | ||
* @var Application Pushover application. | ||
* @var Application pushover application | ||
OskarStark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
private $application; | ||
|
||
/** | ||
* @var Recipient Pushover user. | ||
* @var Recipient pushover user | ||
*/ | ||
private $recipient; | ||
|
||
/** | ||
* @var GlanceDataFields Glance Data Fields. | ||
* @var GlanceDataFields glance Data Fields | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to go through such changes, review them and move description to the top please? E.g.:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will check in the next days There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be moved anyway when we add native types. From this point on it is superfluous for Cs-Fixer and it will be removed, resulting in the plain description as comment. |
||
private $glanceDataFields; | ||
|
||
|
@@ -52,73 +52,49 @@ public function __construct(Application $application, GlanceDataFields $glanceDa | |
$this->glanceDataFields = $glanceDataFields; | ||
} | ||
|
||
/** | ||
* @return Application | ||
*/ | ||
public function getApplication(): Application | ||
{ | ||
return $this->application; | ||
} | ||
|
||
/** | ||
* @param Application $application | ||
*/ | ||
public function setApplication(Application $application): void | ||
{ | ||
$this->application = $application; | ||
} | ||
|
||
/** | ||
* @return Recipient | ||
*/ | ||
public function getRecipient(): Recipient | ||
{ | ||
return $this->recipient; | ||
} | ||
|
||
/** | ||
* @param Recipient $recipient | ||
*/ | ||
public function setRecipient(Recipient $recipient): void | ||
{ | ||
$this->recipient = $recipient; | ||
} | ||
|
||
/** | ||
* @return GlanceDataFields | ||
*/ | ||
public function getGlanceDataFields(): GlanceDataFields | ||
{ | ||
return $this->glanceDataFields; | ||
} | ||
|
||
/** | ||
* @param GlanceDataFields $glanceDataFields | ||
*/ | ||
public function setGlanceDataFields(GlanceDataFields $glanceDataFields): void | ||
{ | ||
$this->glanceDataFields = $glanceDataFields; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasAtLeastOneField(): bool | ||
{ | ||
if (null === $this->getGlanceDataFields()->getTitle() && | ||
null === $this->getGlanceDataFields()->getSubtext() && | ||
null === $this->getGlanceDataFields()->getCount() && | ||
null === $this->getGlanceDataFields()->getPercent() | ||
if (null === $this->getGlanceDataFields()->getTitle() | ||
&& null === $this->getGlanceDataFields()->getSubtext() | ||
&& null === $this->getGlanceDataFields()->getCount() | ||
&& null === $this->getGlanceDataFields()->getPercent() | ||
) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasRecipient(): bool | ||
{ | ||
if (null === $this->recipient) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be upgraded to v3 across the whole file afterwards