generated from ergebnis/php-cs-fixer-config-template
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #871 from ergebnis/feature/php-version
Enhancement: Extract `PhpVersion` as value object
- Loading branch information
Showing
42 changed files
with
910 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config; | ||
|
||
final class PhpVersion | ||
{ | ||
private readonly PhpVersion\Major $major; | ||
private readonly PhpVersion\Minor $minor; | ||
private readonly PhpVersion\Patch $patch; | ||
|
||
private function __construct( | ||
PhpVersion\Major $major, | ||
PhpVersion\Minor $minor, | ||
PhpVersion\Patch $patch, | ||
) { | ||
$this->major = $major; | ||
$this->minor = $minor; | ||
$this->patch = $patch; | ||
} | ||
|
||
public static function create( | ||
PhpVersion\Major $major, | ||
PhpVersion\Minor $minor, | ||
PhpVersion\Patch $patch, | ||
): self { | ||
return new self( | ||
$major, | ||
$minor, | ||
$patch, | ||
); | ||
} | ||
|
||
public static function current(): self | ||
{ | ||
return new self( | ||
PhpVersion\Major::fromInt(\PHP_MAJOR_VERSION), | ||
PhpVersion\Minor::fromInt(\PHP_MINOR_VERSION), | ||
PhpVersion\Patch::fromInt(\PHP_RELEASE_VERSION), | ||
); | ||
} | ||
|
||
/** | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public static function fromInt(int $value): self | ||
{ | ||
if (0 > $value) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value needs to be greater than or equal to 0, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
|
||
$major = \intdiv( | ||
$value, | ||
10_000, | ||
); | ||
|
||
$minor = \intdiv( | ||
$value - $major * 10_000, | ||
100, | ||
); | ||
|
||
$patch = $value - $major * 10_000 - $minor * 100; | ||
|
||
return new self( | ||
PhpVersion\Major::fromInt($major), | ||
PhpVersion\Minor::fromInt($minor), | ||
PhpVersion\Patch::fromInt($patch), | ||
); | ||
} | ||
|
||
public function major(): PhpVersion\Major | ||
{ | ||
return $this->major; | ||
} | ||
|
||
public function minor(): PhpVersion\Minor | ||
{ | ||
return $this->minor; | ||
} | ||
|
||
public function patch(): PhpVersion\Patch | ||
{ | ||
return $this->patch; | ||
} | ||
|
||
public function toInt(): int | ||
{ | ||
return $this->major->toInt() * 10_000 + $this->minor->toInt() * 100 + $this->patch->toInt(); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return \sprintf( | ||
'%d.%d.%d', | ||
$this->major->toInt(), | ||
$this->minor->toInt(), | ||
$this->patch->toInt(), | ||
); | ||
} | ||
|
||
public function isSmallerThan(self $other): bool | ||
{ | ||
return $this->toInt() < $other->toInt(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\PhpVersion; | ||
|
||
final class Major | ||
{ | ||
private readonly int $value; | ||
|
||
private function __construct(int $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public static function fromInt(int $value): self | ||
{ | ||
if (0 > $value) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value needs to greater than or equal to 0, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
public function toInt(): int | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\PhpVersion; | ||
|
||
final class Minor | ||
{ | ||
private readonly int $value; | ||
|
||
private function __construct(int $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public static function fromInt(int $value): self | ||
{ | ||
if (0 > $value) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value needs to be a greater than or equal to 0, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
|
||
if (99 < $value) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value needs to be a less than or equal to 99, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
public function toInt(): int | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2019-2023 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/php-cs-fixer-config | ||
*/ | ||
|
||
namespace Ergebnis\PhpCsFixer\Config\PhpVersion; | ||
|
||
final class Patch | ||
{ | ||
private readonly int $value; | ||
|
||
private function __construct(int $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public static function fromInt(int $value): self | ||
{ | ||
if (0 > $value) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value needs to be a greater than or equal to 0, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
|
||
if (99 < $value) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value needs to be a less than or equal to 99, but %d is not.', | ||
$value, | ||
)); | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
public function toInt(): int | ||
{ | ||
return $this->value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.