Skip to content

Commit

Permalink
more constructor propery promotion (#309)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Jun 1, 2023
1 parent dd32d3b commit 88bb611
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Expand Up @@ -15,10 +15,12 @@ All notable changes to this project will be documented in this file.
* Style
* Applied latest PHP Coding Standards (via [#302])
Some parameters allow nullables implicitly, was explicitly.
* Wrote some class properties with constructor promotion (via [#309])

[#302]: https://github.com/CycloneDX/cyclonedx-php-library/pull/302
[#305]: https://github.com/CycloneDX/cyclonedx-php-library/issues/305
[#306]: https://github.com/CycloneDX/cyclonedx-php-library/pull/306
[#309]: https://github.com/CycloneDX/cyclonedx-php-library/pull/309

## 2.1.2 - 2023-04-05

Expand Down
8 changes: 3 additions & 5 deletions src/Core/Serialization/DOM/_BaseNormalizer.php
Expand Up @@ -33,11 +33,9 @@
*/
abstract class _BaseNormalizer
{
private readonly NormalizerFactory $normalizerFactory;

public function __construct(NormalizerFactory $normalizerFactory)
{
$this->normalizerFactory = $normalizerFactory;
public function __construct(
private readonly NormalizerFactory $normalizerFactory
) {
}

public function getNormalizerFactory(): NormalizerFactory
Expand Down
8 changes: 3 additions & 5 deletions src/Core/Serialization/JSON/_BaseNormalizer.php
Expand Up @@ -33,11 +33,9 @@
*/
abstract class _BaseNormalizer
{
private readonly NormalizerFactory $normalizerFactory;

public function __construct(NormalizerFactory $normalizerFactory)
{
$this->normalizerFactory = $normalizerFactory;
public function __construct(
private readonly NormalizerFactory $normalizerFactory
) {
}

public function getNormalizerFactory(): NormalizerFactory
Expand Down
10 changes: 4 additions & 6 deletions src/Core/Validation/BaseValidator.php
Expand Up @@ -30,12 +30,10 @@
*/
abstract class BaseValidator implements Validator
{
/** @TODO in next major version: use `\CycloneDX\Core\Enums\Version` */
private readonly Spec $spec;

public function __construct(Spec $spec)
{
$this->spec = $spec;
public function __construct(
/* @TODO in next major version: use `\CycloneDX\Core\Enums\Version` instead of `Spec` */
private readonly Spec $spec
) {
}

public function getSpec(): Spec
Expand Down
8 changes: 3 additions & 5 deletions src/Core/Validation/ValidationError.php
Expand Up @@ -30,16 +30,14 @@
*/
class ValidationError
{
private readonly string $message;

/**
* keep for internal debug purposes.
*/
protected ?object $error = null;

final protected function __construct(string $message)
{
$this->message = $message;
final protected function __construct(
private readonly string $message
) {
}

public function getMessage(): string
Expand Down

0 comments on commit 88bb611

Please sign in to comment.