Skip to content
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

update coding standard #187

Merged
merged 1 commit into from
May 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

uses: "mimmi20/template/.github/workflows/ci.yml@master"
with:
extensions: "dom, iconv, mbstring, simplexml, tokenizer, xml, xmlwriter"
extensions: "ctype, dom, iconv, mbstring, simplexml, tokenizer, xml, xmlwriter"
ini-values: "opcache.enable=1, opcache.fast_shutdown=0, zend.assertions=1, assert.exception=On, intl.default_locale=de, intl.use_exceptions=1, zend.exception_ignore_args=0"
composer-options: "--optimize-autoloader --prefer-dist --prefer-stable -v"
composer-outdated-option: ""
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
->name('*.php')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->append([__DIR__ . '/rector.php'])
->append([__FILE__]);

$rules = require 'vendor/mimmi20/coding-standard/src/php-cs-fixer.config.php';
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@
"ext-mbstring": "*"
},
"require-dev": {
"ext-ctype": "*",
"ext-dom": "*",
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
"infection/infection": "^0.26.21",
"mimmi20/coding-standard": "^4.0.5",
"mimmi20/coding-standard": "^5.0.0",
"nikic/php-parser": "^v4.15.4",
"phpstan/extension-installer": "^1.3.0",
"phpstan/phpstan": "^1.10.14",
"phpstan/phpstan-deprecation-rules": "^1.1.3",
"phpstan/phpstan-phpunit": "^1.3.11",
"phpunit/phpunit": "^10.1.2"
"phpunit/phpunit": "^10.1.2",
"rector/rector": "^0.15.25"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<file>src</file>
<file>tests</file>
<file>.php-cs-fixer.php</file>
<file>rector.php</file>
</ruleset>
36 changes: 29 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
<?php
/**
* This file is part of the mimmi20/contact package.
*
* Copyright (c) 2022-2023, Thomas Mueller <mimmi20@live.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);
declare(strict_types = 1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Php80\Rector\FunctionLike\UnionTypesRector;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
//$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
// $rectorConfig->rule(\Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\InlineConstructorDefaultToPropertyRector::class);

$rectorConfig->sets([
SetList::DEAD_CODE,
LevelSetList::UP_TO_PHP_81,
PHPUnitSetList::PHPUNIT_100,
]);

// define sets of rules
// $rectorConfig->sets([
// LevelSetList::UP_TO_PHP_81
// ]);
$rectorConfig->skip(
[
UnionTypesRector::class,
NullToStrictStringFuncCallArgRector::class,
RemoveDeadInstanceOfRector::class,
FirstClassCallableRector::class,
RemoveAlwaysTrueIfConditionRector::class,
RemoveParentCallWithoutParentRector::class,
CountOnNullRector::class,
],
);
};
16 changes: 8 additions & 8 deletions src/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,23 @@ public function toArray(): array
{
$birthdate = $this->getBirthdate();

if (null !== $birthdate) {
if ($birthdate !== null) {
$birthdate = $birthdate->format('Y-m-d');
}

return [
'birthdate' => $birthdate,
'city' => $this->getCity(),
'contactId' => $this->getContactId(),
'salutation' => $this->getSalutation(),
'firstname' => $this->getFirstname(),
'email' => $this->getEmail(),
'familyname' => $this->getFamilyname(),
'street' => $this->getStreet(),
'firstname' => $this->getFirstname(),
'housenumber' => $this->getHousenumber(),
'postalcode' => $this->getPostalcode(),
'city' => $this->getCity(),
'birthdate' => $birthdate,
'phonenumber' => $this->getPhonenumber(),
'email' => $this->getEmail(),
'postalcode' => $this->getPostalcode(),
'profession' => $this->getProfession(),
'salutation' => $this->getSalutation(),
'street' => $this->getStreet(),
];
}
}
14 changes: 7 additions & 7 deletions tests/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,18 @@ public function testToArray(): void
$this->object->setProfession($profession);

$expected = [
'birthdate' => $birthdate->format('Y-m-d'),
'city' => $city,
'contactId' => $id,
'salutation' => $salutation,
'firstname' => $firstname,
'email' => $email,
'familyname' => $familyname,
'street' => $street,
'firstname' => $firstname,
'housenumber' => $housenumber,
'postalcode' => $postalcode,
'city' => $city,
'birthdate' => $birthdate->format('Y-m-d'),
'phonenumber' => $phonenumber,
'email' => $email,
'postalcode' => $postalcode,
'profession' => $profession,
'salutation' => $salutation,
'street' => $street,
];

self::assertSame($expected, $this->object->toArray());
Expand Down