Skip to content

Commit

Permalink
Update CS to PER
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Sep 3, 2022
1 parent 6ab0db1 commit f5f459b
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 112 deletions.
3 changes: 3 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
'separate' => 'none',
'header' => "Box packing (3D bin packing, knapsack problem).\n\n@author Doug Wright",
],
'phpdoc_line_span' => true,
'phpdoc_to_comment' => false,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'none'],
]
)
->setRiskyAllowed(true)
Expand Down
7 changes: 4 additions & 3 deletions src/BoxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
class BoxList implements IteratorAggregate
{
/** @var Box[] */
/**
* @var Box[]
*/
private array $list = [];

private bool $isSorted = false;
Expand All @@ -34,8 +36,7 @@ public function __construct(?BoxSorter $sorter = null)
/**
* Do a bulk create.
*
* @param Box[] $boxes
* @return BoxList
* @param Box[] $boxes
*/
public static function fromArray(array $boxes, bool $preSorted = false): self
{
Expand Down
25 changes: 9 additions & 16 deletions src/ItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,30 @@

namespace DVDoug\BoxPacker;

use ArrayIterator;
use Countable;
use IteratorAggregate;
use Traversable;

use function array_key_last;
use function array_pop;
use function array_reverse;
use function array_slice;

use ArrayIterator;

use function count;

use Countable;

use function current;
use function end;

use IteratorAggregate;

use function key;
use function prev;

use Traversable;

use function usort;

/**
* List of items to be packed, ordered by volume.
*/
class ItemList implements Countable, IteratorAggregate
{
/** @var Item[] */
/**
* @var Item[]
*/
private array $list = [];

private bool $isSorted = false;
Expand All @@ -55,8 +50,7 @@ public function __construct(?ItemSorter $sorter = null)
/**
* Do a bulk create.
*
* @param Item[] $items
* @return ItemList
* @param Item[] $items
*/
public static function fromArray(array $items, bool $preSorted = false): self
{
Expand Down Expand Up @@ -148,7 +142,6 @@ public function top(): Item

/**
* @internal
* @return ItemList
*/
public function topN(int $n): self
{
Expand Down
7 changes: 3 additions & 4 deletions src/LayerPacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

namespace DVDoug\BoxPacker;

use function array_merge;
use function iterator_to_array;
use function max;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

use function array_merge;
use function iterator_to_array;
use function max;
use function sort;

/**
Expand Down
11 changes: 7 additions & 4 deletions src/OrientatedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

namespace DVDoug\BoxPacker;

use function atan;

use JsonSerializable;

use function atan;
use function min;
use function sort;

Expand All @@ -30,10 +29,14 @@ class OrientatedItem implements JsonSerializable

protected int $surfaceFootprint;

/** @var array<string, bool> */
/**
* @var array<string, bool>
*/
protected static array $stabilityCache = [];

/** @var int[] */
/**
* @var int[]
*/
protected array $dimensionsAsArray;

public function __construct(Item $item, int $width, int $length, int $depth)
Expand Down
9 changes: 5 additions & 4 deletions src/OrientatedItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

namespace DVDoug\BoxPacker;

use function array_filter;
use function count;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

use function array_filter;
use function count;
use function usort;

/**
Expand All @@ -29,7 +28,9 @@ class OrientatedItemFactory implements LoggerAwareInterface

protected bool $singlePassMode = false;

/** @var array<string, bool> */
/**
* @var array<string, bool>
*/
protected static array $emptyBoxStableItemOrientationCache = [];

public function __construct(Box $box)
Expand Down
8 changes: 5 additions & 3 deletions src/OrientatedItemSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace DVDoug\BoxPacker;

use Psr\Log\LoggerInterface;

use function max;
use function min;

use const PHP_INT_MAX;

use Psr\Log\LoggerInterface;

/**
* Figure out best choice of orientations for an item and a given context.
* @internal
Expand All @@ -23,7 +23,9 @@ class OrientatedItemSorter
{
private LoggerInterface $logger;

/** @var array<string, int> */
/**
* @var array<string, int>
*/
protected static array $lookaheadCache = [];

private OrientatedItemFactory $orientatedItemFactory;
Expand Down
5 changes: 2 additions & 3 deletions src/PackedBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

namespace DVDoug\BoxPacker;

use function iterator_to_array;
use function json_encode;

use JsonSerializable;

use function iterator_to_array;
use function json_encode;
use function max;
use function round;
use function urlencode;
Expand Down
16 changes: 6 additions & 10 deletions src/PackedBoxList.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@
namespace DVDoug\BoxPacker;

use ArrayIterator;

use function count;

use Countable;
use IteratorAggregate;

use function json_encode;

use JsonSerializable;
use Traversable;

use function count;
use function json_encode;
use function reset;
use function round;

use Traversable;

use function urlencode;
use function usort;

Expand All @@ -32,7 +26,9 @@
*/
class PackedBoxList implements IteratorAggregate, Countable, JsonSerializable
{
/** @var PackedBox[] */
/**
* @var PackedBox[]
*/
private array $list = [];

private bool $isSorted = false;
Expand Down
3 changes: 0 additions & 3 deletions src/PackedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ public function getVolume(): int
return $this->width * $this->length * $this->depth;
}

/**
* @return PackedItem
*/
public static function fromOrientatedItem(OrientatedItem $orientatedItem, int $x, int $y, int $z): self
{
return new self(
Expand Down
11 changes: 5 additions & 6 deletions src/PackedItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@

namespace DVDoug\BoxPacker;

use function array_map;

use ArrayIterator;

use function count;

use Countable;
use IteratorAggregate;
use Traversable;

use function array_map;
use function count;
use function usort;

/**
* List of packed items, ordered by volume.
*/
class PackedItemList implements Countable, IteratorAggregate
{
/** @var PackedItem[] */
/**
* @var PackedItem[]
*/
private array $list = [];

private int $weight = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/PackedLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class PackedLayer

private int $weight = 0;

/** @var PackedItem[] */
/**
* @var PackedItem[]
*/
protected array $items = [];

/**
Expand Down
17 changes: 8 additions & 9 deletions src/Packer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@

namespace DVDoug\BoxPacker;

use function array_merge;
use function array_pop;
use function count;

use DVDoug\BoxPacker\Exception\NoBoxesAvailableException;

use const PHP_INT_MAX;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Psr\Log\NullLogger;
use WeakMap;

use function array_merge;
use function array_pop;
use function count;
use function usort;

use WeakMap;
use const PHP_INT_MAX;

/**
* Actual packer.
Expand All @@ -38,7 +35,9 @@ class Packer implements LoggerAwareInterface

protected BoxList $boxes;

/** @var WeakMap<Box, int> */
/**
* @var WeakMap<Box, int>
*/
protected WeakMap $boxQuantitiesAvailable;

protected PackedBoxSorter $packedBoxSorter;
Expand Down
7 changes: 3 additions & 4 deletions src/VolumePacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

namespace DVDoug\BoxPacker;

use function array_map;
use function count;
use function max;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

use function array_map;
use function count;
use function max;
use function reset;
use function usort;

Expand Down
18 changes: 9 additions & 9 deletions src/WeightRedistributor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@

namespace DVDoug\BoxPacker;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Psr\Log\NullLogger;
use WeakMap;

use function array_filter;
use function array_map;
use function array_merge;
use function array_sum;
use function assert;
use function count;
use function iterator_to_array;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Psr\Log\NullLogger;

use function usort;

use WeakMap;

/**
* Actual packer.
* @internal
Expand All @@ -35,7 +33,9 @@ class WeightRedistributor implements LoggerAwareInterface

private BoxList $boxes;

/** @var WeakMap<Box, int> */
/**
* @var WeakMap<Box, int>
*/
private WeakMap $boxQuantitiesAvailable;

private PackedBoxSorter $packedBoxSorter;
Expand Down

0 comments on commit f5f459b

Please sign in to comment.