Skip to content

Commit

Permalink
refactor: codacy quality checks
Browse files Browse the repository at this point in the history
  • Loading branch information
vuryss committed Jun 24, 2024
1 parent 7cd068d commit 99faa2b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
Empty file added .codacy.yml
Empty file.
11 changes: 8 additions & 3 deletions .github/workflows/codecov.yml → .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Codecov code coverage
name: Code coverage
on: [push, pull_request]
jobs:
run:
Expand All @@ -7,14 +7,19 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Set up php 8.3
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@2e947f1f6932d141d076ca441d0e1e881775e95b
with:
php-version: '8.3'
- name: Install dependencies
run: composer self-update && composer install && composer dump-autoload
- name: Run tests and collect coverage
run: vendor/bin/pest --coverage-clover coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to codacy
uses: codacy/codacy-coverage-reporter-action@89d6c85cfafaec52c72b6c5e8b2878d33104c699
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-report: coverage.xml
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Set up php 8.3
uses: shivammathur/setup-php@v2
uses: shivammathur/setup-php@2e947f1f6932d141d076ca441d0e1e881775e95b
with:
php-version: '8.3'
- name: Install dependencies
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

[![Tests](https://github.com/vuryss/serializer/workflows/Tests/badge.svg)](https://github.com/vuryss/serializer/actions?query=workflow:"Tests")
[![codecov](https://codecov.io/gh/vuryss/serializer/graph/badge.svg?token=kK0ZHh3raA)](https://codecov.io/gh/vuryss/serializer)
[![Latest Stable Version](http://poser.pugx.org/vuryss/serializer/v)](https://packagist.org/packages/vuryss/serializer)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/760e3d4f985248fd8bb47b947873b847)](https://app.codacy.com/gh/vuryss/serializer/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
![GitHub Release](https://img.shields.io/github/v/release/vuryss/serializer)
[![License](http://poser.pugx.org/vuryss/serializer/license)](https://packagist.org/packages/vuryss/serializer)
[![PHP Version Require](http://poser.pugx.org/vuryss/serializer/require/php)](https://packagist.org/packages/vuryss/serializer)

Expand Down Expand Up @@ -41,7 +42,7 @@ $person = $serializer->deserialize($json, Person::class);

### Caching - optional, but highly recommended, otherwise the library will be slow

Supports PSR-6 CacheItemPoolInterface: https://www.php-fig.org/psr/psr-6/#cacheitempoolinterface
Supports PSR-6 CacheItemPoolInterface: <https://www.php-fig.org/psr/psr-6/#cacheitempoolinterface>

No need to chain in-memory cache with external cache, the library will do it for you.
Cache will be called once per used class (used in serialization or deserialization), then will be cached in memory until the script ends.
Expand Down Expand Up @@ -107,6 +108,7 @@ $serializer = new Serializer(
```

### Handling of NULL values

- By default, NULL values are included in the serialized value.

To disable this you can use the `SerializerInterface::ATTRIBUTE_SKIP_NULL_VALUES` attribute:
Expand Down
8 changes: 3 additions & 5 deletions src/Denormalizer/ObjectDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ public function denormalize(mixed $data, DataType $type, Denormalizer $denormali
}
}

if (count($constructorParameters) > 0) {
$instance = $this->initializeWithConstructor($className, $classMetadata->constructor, $constructorParameters);
} else {
$instance = new $className();
}
$instance = count($constructorParameters) > 0
? $this->initializeWithConstructor($className, $classMetadata->constructor, $constructorParameters)
: new $className();

foreach ($directAssignmentProperties as $name => $value) {
$instance->{$name} = $value;
Expand Down

0 comments on commit 99faa2b

Please sign in to comment.