Skip to content

Commit

Permalink
Readonly classes for PackedBox and PackedItem
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Dec 4, 2023
1 parent 2edc23e commit 0a49fe6
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 32 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
php-version:
- "8.3"
- "8.2"
- "8.1"

dependencies:
- "highest"
Expand Down Expand Up @@ -69,7 +68,7 @@ jobs:
php-${{ matrix.php-version }}-deps-${{ matrix.dependencies }}
- name: Remove PHP-CS-Fixer if not called
if: matrix.php-version != '8.1' || matrix.dependencies != 'highest'
if: matrix.php-version != '8.2' || matrix.dependencies != 'highest'
run: composer remove --dev --no-update "friendsofphp/php-cs-fixer";

- name: Install dependencies (low)
Expand Down Expand Up @@ -100,7 +99,7 @@ jobs:
- name: PHPUnit
run: |
if [ "${{ matrix.php-version }}" = "8.1" ] && [ "${{ matrix.dependencies }}" = "highest" ]; then
if [ "${{ matrix.php-version }}" = "8.2" ] && [ "${{ matrix.dependencies }}" = "highest" ]; then
php -dmemory_limit=-1 vendor/phpunit/phpunit/phpunit --exclude-group=efficiency;
composer global require scrutinizer/ocular;
~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage-phpunit/clover.xml;
Expand All @@ -110,15 +109,15 @@ jobs:
- name: Behat
run: |
if [ "${{ matrix.php-version }}" = "8.1" ] && [ "${{ matrix.dependencies }}" = "highest" ]; then
if [ "${{ matrix.php-version }}" = "8.2" ] && [ "${{ matrix.dependencies }}" = "highest" ]; then
php -dmemory_limit=-1 vendor/behat/behat/bin/behat --strict;
~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage-behat/clover.xml;
else
php -dmemory_limit=-1 vendor/behat/behat/bin/behat --strict --no-coverage;
fi;
- name: Check code style
if: matrix.php-version == '8.1' && matrix.dependencies == 'highest'
if: matrix.php-version == '8.2' && matrix.dependencies == 'highest'
run: vendor/bin/php-cs-fixer fix --verbose --dry-run --diff --allow-risky=yes --format=checkstyle | cs2pr


Expand All @@ -132,7 +131,6 @@ jobs:
php-version:
- "8.3"
- "8.2"
- "8.1"

dependencies:
- "highest"
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'@Symfony:risky' => true,
'@PHP80Migration:risky' => true,
'@PHP81Migration' => true,
'@PHP82Migration' => true,
'concat_space' => ['spacing' => 'one'],
'fopen_flags' => ['b_mode' => true],
'native_function_invocation' => ['include' => ['@all']],
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build:
environment:
# Languages
php:
version: "8.1"
version: "8.2"
ini:
memory_limit: "-1"

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
exceptions are disabled).

### Changed
- Minimum PHP version is now 8.1
- Minimum PHP version is now 8.2
- Exceptions are now in the `DVDoug\BoxPacker\Exception` namespace (previously `DVDoug\BoxPacker`)
- The signature of the `canBePacked` method on the `ConstrainedPlacementItem` interface has been changed to replace the
first two arguments(`Box $box`, `PackedItemList $alreadyPackedItems`) with `PackedBox $packedBox`. This allows
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
],
"license": "MIT",
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-json": "*",
"psr/log": "^1.0||^2.0||^3.0"
},
"require-dev": {
"behat/behat": "^3.13",
"dvdoug/behat-code-coverage": "^5.3.1",
"friendsofphp/php-cs-fixer": "^3.22.0",
"monolog/monolog": "^3.4",
"phpunit/phpunit": "^10.2"
"friendsofphp/php-cs-fixer": "^3.38.2",
"monolog/monolog": "^3.5",
"phpunit/phpunit": "^10.4"
},
"config": {
"preferred-install": {
Expand All @@ -38,7 +38,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-master": "4.x-dev"
}
}
}
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you don't want to use Composer, the code is available to download from `GitHu

Requirements
------------
BoxPacker v4 is compatible with PHP 8.1+
BoxPacker v4 is compatible with PHP 8.2+

Versioning
----------
Expand Down
8 changes: 4 additions & 4 deletions src/PackedBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
/**
* A "box" with items.
*/
class PackedBox implements JsonSerializable
readonly class PackedBox implements JsonSerializable
{
protected readonly int $itemWeight;
protected int $itemWeight;

protected readonly float $volumeUtilisation;
protected float $volumeUtilisation;

/**
* Get packed weight.
Expand Down Expand Up @@ -202,7 +202,7 @@ public function generateVisualisationURL(): string
return 'https://boxpacker.io/en/master/visualiser.html?packing=' . json_encode($data, flags: JSON_THROW_ON_ERROR | JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}

public function __construct(public readonly Box $box, public readonly PackedItemList $items)
public function __construct(public Box $box, public PackedItemList $items)
{
assert($this->assertPackingCompliesWithRealWorld());
}
Expand Down
18 changes: 9 additions & 9 deletions src/PackedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
/**
* A packed item.
*/
class PackedItem implements JsonSerializable
readonly class PackedItem implements JsonSerializable
{
public readonly int $volume;
public int $volume;

public function __construct(
public readonly Item $item,
public readonly int $x,
public readonly int $y,
public readonly int $z,
public readonly int $width,
public readonly int $length,
public readonly int $depth
public Item $item,
public int $x,
public int $y,
public int $z,
public int $width,
public int $length,
public int $depth
) {
}

Expand Down
10 changes: 5 additions & 5 deletions src/WorkingVolume.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* Class WorkingVolume.
* @internal
*/
class WorkingVolume implements Box, JsonSerializable
readonly class WorkingVolume implements Box, JsonSerializable
{
public function __construct(
private readonly int $width,
private readonly int $length,
private readonly int $depth,
private readonly int $maxWeight
private int $width,
private int $length,
private int $depth,
private int $maxWeight
) {
}

Expand Down

0 comments on commit 0a49fe6

Please sign in to comment.