GGGGino /
WarehousePath
| 1 | <?php |
||
| 2 | |||
| 3 | namespace GGGGino\WarehousePath; |
||
| 4 | |||
| 5 | use GGGGino\WarehousePath\Entity\Corridor; |
||
| 6 | use GGGGino\WarehousePath\Entity\Location; |
||
| 7 | use GGGGino\WarehousePath\Entity\Place; |
||
| 8 | use GGGGino\WarehousePath\Entity\PlaceType; |
||
| 9 | use GGGGino\WarehousePath\Entity\Wall; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Class PlacesCollector |
||
| 13 | * @package GGGGino\WarehousePath |
||
| 14 | */ |
||
| 15 | class PlacesCollector |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var PlaceType[] |
||
| 19 | */ |
||
| 20 | private $placeTypes; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Place[] |
||
| 24 | */ |
||
| 25 | private $places = array(); |
||
| 26 | |||
| 27 | public function __construct() |
||
| 28 | { |
||
| 29 | $this->placeTypes = array(); |
||
| 30 | $this->places = array(); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return PlaceType[] |
||
| 35 | */ |
||
| 36 | public function getPlacesType() |
||
| 37 | { |
||
| 38 | return $this->placeTypes; |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param PlaceType[] $placeTypes |
||
| 43 | * @return PlacesCollector |
||
| 44 | */ |
||
| 45 | public function setPlacesType($placeTypes) |
||
| 46 | { |
||
| 47 | $this->placeTypes = $placeTypes; |
||
| 48 | return $this; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param $placeType |
||
| 53 | * @return $this |
||
| 54 | */ |
||
| 55 | public function addPlaceType($placeType) |
||
| 56 | { |
||
| 57 | $this->placeTypes[] = $placeType; |
||
| 58 | return $this; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return $this |
||
| 63 | */ |
||
| 64 | public function addBasePlaceTypes() |
||
| 65 | { |
||
| 66 | $this->addPlaceType(new Location()); |
||
| 67 | $this->addPlaceType(new Corridor()); |
||
| 68 | $this->addPlaceType(new Wall()); |
||
| 69 | |||
| 70 | return $this; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get the placeType from a give classname |
||
| 75 | * |
||
| 76 | * @param $class |
||
| 77 | * @return Place |
||
| 78 | */ |
||
| 79 | public function &getPlaceTypeByClass($class) |
||
| 80 | { |
||
| 81 | /** @var Place $placeType */ |
||
| 82 | foreach ($this->placeTypes as $placeType) { |
||
| 83 | if ($placeType instanceof $class) { |
||
| 84 | return $placeType; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | return null; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param $weight |
||
| 93 | * @return Place |
||
| 94 | */ |
||
| 95 | public function &getPlaceTypeByWeight($weight) |
||
| 96 | { |
||
| 97 | /** @var Place $placeType */ |
||
| 98 | foreach ($this->placeTypes as $placeType) { |
||
| 99 | if ($weight == $placeType->getOriginalWeight()) { |
||
| 100 | return $placeType; |
||
|
0 ignored issues
–
show
|
|||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | return null; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Reset all the node to permit another calculation |
||
| 109 | */ |
||
| 110 | public function reset() |
||
| 111 | { |
||
| 112 | foreach ($this->places as $place) { |
||
| 113 | $place->reset(); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return Place[] |
||
| 119 | */ |
||
| 120 | public function getPlaces(): array |
||
| 121 | { |
||
| 122 | return $this->places; |
||
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param Place[] $places |
||
| 127 | * @return PlacesCollector |
||
| 128 | */ |
||
| 129 | public function setPlaces($places) |
||
| 130 | { |
||
| 131 | $this->places = $places; |
||
| 132 | return $this; |
||
| 133 | } |
||
| 134 | } |