@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | // Walk every item in the PlaceArray and if I find one equal I use that as strating point |
| 23 | 23 | foreach ($arrayNodes as $key => $node) { |
| 24 | - if ( $node === $startingPoint ) { |
|
| 24 | + if ($node === $startingPoint) { |
|
| 25 | 25 | $arrayNodeKey = $key; |
| 26 | 26 | break; |
| 27 | 27 | } |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | /** @var int $nodeWeight */ |
| 36 | 36 | foreach ($matrix[$arrayNodeKey] as $key => $nodeWeight) { |
| 37 | - if( $key == $arrayNodeKey ) |
|
| 37 | + if ($key == $arrayNodeKey) |
|
| 38 | 38 | continue; |
| 39 | 39 | |
| 40 | - if( $minimumFound > $nodeWeight ){ |
|
| 40 | + if ($minimumFound > $nodeWeight) { |
|
| 41 | 41 | $minimumFound = $nodeWeight; |
| 42 | 42 | $minimumFoundKey = $key; |
| 43 | 43 | } |
@@ -34,8 +34,9 @@ |
||
| 34 | 34 | |
| 35 | 35 | /** @var int $nodeWeight */ |
| 36 | 36 | foreach ($matrix[$arrayNodeKey] as $key => $nodeWeight) { |
| 37 | - if( $key == $arrayNodeKey ) |
|
| 38 | - continue; |
|
| 37 | + if( $key == $arrayNodeKey ) { |
|
| 38 | + continue; |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | 41 | if( $minimumFound > $nodeWeight ){ |
| 41 | 42 | $minimumFound = $nodeWeight; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public static function createFromJson($path) |
| 46 | 46 | { |
| 47 | - if( !$path ) |
|
| 47 | + if (!$path) |
|
| 48 | 48 | throw new \Exception('Please select a path'); |
| 49 | 49 | |
| 50 | 50 | $placesCollector = new PlacesCollector(); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public static function createFromMatrix($param) |
| 67 | 67 | { |
| 68 | - if( !is_array($param) ) |
|
| 68 | + if (!is_array($param)) |
|
| 69 | 69 | throw new \Exception('Matrix should be initialized with an array'); |
| 70 | 70 | |
| 71 | 71 | $placesCollector = new PlacesCollector(); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public static function createFromTree($param) |
| 88 | 88 | { |
| 89 | - if( !is_array($param) ) |
|
| 89 | + if (!is_array($param)) |
|
| 90 | 90 | throw new \Exception('Matrix should be initialized with an array'); |
| 91 | 91 | |
| 92 | 92 | $placesCollector = new PlacesCollector(); |
@@ -189,17 +189,17 @@ discard block |
||
| 189 | 189 | /** @var Place[][] $resultMatrix */ |
| 190 | 190 | $resultMatrix = array(); |
| 191 | 191 | |
| 192 | - if ( empty($places) ) |
|
| 192 | + if (empty($places)) |
|
| 193 | 193 | throw new \Exception('First add the places'); |
| 194 | 194 | |
| 195 | 195 | /** @var Place $startingPlace */ |
| 196 | 196 | $startingPlace = reset($places); |
| 197 | 197 | |
| 198 | - while ( $newPlace = $startingPlace->getTopRef() ) { |
|
| 198 | + while ($newPlace = $startingPlace->getTopRef()) { |
|
| 199 | 199 | $startingPlace = $newPlace; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - while ( $newPlace = $startingPlace->getLeftRef() ) { |
|
| 202 | + while ($newPlace = $startingPlace->getLeftRef()) { |
|
| 203 | 203 | $startingPlace = $newPlace; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -44,8 +44,9 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public static function createFromJson($path) |
| 46 | 46 | { |
| 47 | - if( !$path ) |
|
| 48 | - throw new \Exception('Please select a path'); |
|
| 47 | + if( !$path ) { |
|
| 48 | + throw new \Exception('Please select a path'); |
|
| 49 | + } |
|
| 49 | 50 | |
| 50 | 51 | $placesCollector = new PlacesCollector(); |
| 51 | 52 | $placesCollector->addBasePlaceTypes(); |
@@ -65,8 +66,9 @@ discard block |
||
| 65 | 66 | */ |
| 66 | 67 | public static function createFromMatrix($param) |
| 67 | 68 | { |
| 68 | - if( !is_array($param) ) |
|
| 69 | - throw new \Exception('Matrix should be initialized with an array'); |
|
| 69 | + if( !is_array($param) ) { |
|
| 70 | + throw new \Exception('Matrix should be initialized with an array'); |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | $placesCollector = new PlacesCollector(); |
| 72 | 74 | $placesCollector->addBasePlaceTypes(); |
@@ -86,8 +88,9 @@ discard block |
||
| 86 | 88 | */ |
| 87 | 89 | public static function createFromTree($param) |
| 88 | 90 | { |
| 89 | - if( !is_array($param) ) |
|
| 90 | - throw new \Exception('Matrix should be initialized with an array'); |
|
| 91 | + if( !is_array($param) ) { |
|
| 92 | + throw new \Exception('Matrix should be initialized with an array'); |
|
| 93 | + } |
|
| 91 | 94 | |
| 92 | 95 | $placesCollector = new PlacesCollector(); |
| 93 | 96 | $placesCollector->addBasePlaceTypes(); |
@@ -196,8 +199,9 @@ discard block |
||
| 196 | 199 | /** @var Place[][] $resultMatrix */ |
| 197 | 200 | $resultMatrix = array(); |
| 198 | 201 | |
| 199 | - if ( empty($places) ) |
|
| 200 | - throw new \Exception('First add the places'); |
|
| 202 | + if ( empty($places) ) { |
|
| 203 | + throw new \Exception('First add the places'); |
|
| 204 | + } |
|
| 201 | 205 | |
| 202 | 206 | /** @var Place $startingPlace */ |
| 203 | 207 | $startingPlace = reset($places); |
@@ -96,8 +96,9 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function setLeftRef(Place &$leftRef): Place |
| 98 | 98 | { |
| 99 | - if( $this->leftRef ) |
|
| 100 | - return $this; |
|
| 99 | + if( $this->leftRef ) { |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 101 | 102 | |
| 102 | 103 | $this->leftRef = $leftRef; |
| 103 | 104 | $leftRef->setRightRef($this); |
@@ -111,8 +112,9 @@ discard block |
||
| 111 | 112 | */ |
| 112 | 113 | public function setRightRef(Place &$rightRef): Place |
| 113 | 114 | { |
| 114 | - if( $this->rightRef ) |
|
| 115 | - return $this; |
|
| 115 | + if( $this->rightRef ) { |
|
| 116 | + return $this; |
|
| 117 | + } |
|
| 116 | 118 | |
| 117 | 119 | $this->rightRef = $rightRef; |
| 118 | 120 | $rightRef->setLeftRef($this); |
@@ -126,8 +128,9 @@ discard block |
||
| 126 | 128 | */ |
| 127 | 129 | public function setTopRef(Place &$topRef): Place |
| 128 | 130 | { |
| 129 | - if( $this->topRef ) |
|
| 130 | - return $this; |
|
| 131 | + if( $this->topRef ) { |
|
| 132 | + return $this; |
|
| 133 | + } |
|
| 131 | 134 | |
| 132 | 135 | $this->topRef = $topRef; |
| 133 | 136 | $topRef->setBottomRef($this); |
@@ -141,8 +144,9 @@ discard block |
||
| 141 | 144 | */ |
| 142 | 145 | public function setBottomRef(Place &$bottomRef): Place |
| 143 | 146 | { |
| 144 | - if( $this->bottomRef ) |
|
| 145 | - return $this; |
|
| 147 | + if( $this->bottomRef ) { |
|
| 148 | + return $this; |
|
| 149 | + } |
|
| 146 | 150 | |
| 147 | 151 | $this->bottomRef = $bottomRef; |
| 148 | 152 | $bottomRef->setTopRef($this); |
@@ -204,8 +208,9 @@ discard block |
||
| 204 | 208 | public function getWalkableNeighbors() |
| 205 | 209 | { |
| 206 | 210 | return array_filter($this->getNeighbors(), function($place) { |
| 207 | - if( !$place ) |
|
| 208 | - return false; |
|
| 211 | + if( !$place ) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 209 | 214 | |
| 210 | 215 | return $place->isWalkable(); |
| 211 | 216 | }); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | public function __toString() |
| 82 | 82 | { |
| 83 | - return $this->getName() . "-" . $this->getOriginalWeight(); |
|
| 83 | + return $this->getName()."-".$this->getOriginalWeight(); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function setLeftRef(Place &$leftRef): Place |
| 98 | 98 | { |
| 99 | - if( $this->leftRef ) |
|
| 99 | + if ($this->leftRef) |
|
| 100 | 100 | return $this; |
| 101 | 101 | |
| 102 | 102 | $this->leftRef = $leftRef; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function setRightRef(Place &$rightRef): Place |
| 113 | 113 | { |
| 114 | - if( $this->rightRef ) |
|
| 114 | + if ($this->rightRef) |
|
| 115 | 115 | return $this; |
| 116 | 116 | |
| 117 | 117 | $this->rightRef = $rightRef; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function setTopRef(Place &$topRef): Place |
| 128 | 128 | { |
| 129 | - if( $this->topRef ) |
|
| 129 | + if ($this->topRef) |
|
| 130 | 130 | return $this; |
| 131 | 131 | |
| 132 | 132 | $this->topRef = $topRef; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function setBottomRef(Place &$bottomRef): Place |
| 143 | 143 | { |
| 144 | - if( $this->bottomRef ) |
|
| 144 | + if ($this->bottomRef) |
|
| 145 | 145 | return $this; |
| 146 | 146 | |
| 147 | 147 | $this->bottomRef = $bottomRef; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | public function getWalkableNeighbors() |
| 205 | 205 | { |
| 206 | 206 | return array_filter($this->getNeighbors(), function($place) { |
| 207 | - if( !$place ) |
|
| 207 | + if (!$place) |
|
| 208 | 208 | return false; |
| 209 | 209 | |
| 210 | 210 | return $place->isWalkable(); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public static function getMatrixSimple() |
| 23 | 23 | { |
| 24 | - $jsonReader = new JsonReader(getcwd() . "/resources/biggerWarehouse.json"); |
|
| 24 | + $jsonReader = new JsonReader(getcwd()."/resources/biggerWarehouse.json"); |
|
| 25 | 25 | return $jsonReader->readAndParse()['warehouse']; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | protected function execute(InputInterface $input, OutputInterface $output) |
| 46 | 46 | { |
| 47 | - $warehouse = Warehouse::createFromJson(getcwd() . "/resources/biggerWarehouse.json"); |
|
| 47 | + $warehouse = Warehouse::createFromJson(getcwd()."/resources/biggerWarehouse.json"); |
|
| 48 | 48 | |
| 49 | 49 | /** @var Place $nodeStart */ |
| 50 | 50 | $nodeStart = $warehouse->getPlaces()[5]; |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | $table->setRows($calculatedMatrix); |
| 60 | 60 | $table->render(); |
| 61 | 61 | |
| 62 | - $output->writeln("Start: " . $nodeStart->getName()); |
|
| 63 | - $output->writeln("End: " . $nodeEnd->getName()); |
|
| 64 | - $output->writeln("Total path: " . $nodeEnd->getCurrentWeight()); |
|
| 62 | + $output->writeln("Start: ".$nodeStart->getName()); |
|
| 63 | + $output->writeln("End: ".$nodeEnd->getName()); |
|
| 64 | + $output->writeln("Total path: ".$nodeEnd->getCurrentWeight()); |
|
| 65 | 65 | } |
| 66 | 66 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public static function getMatrixSimple() |
| 26 | 26 | { |
| 27 | - $jsonReader = new JsonReader(getcwd() . "/../resources/biggerWarehouse.json"); |
|
| 27 | + $jsonReader = new JsonReader(getcwd()."/../resources/biggerWarehouse.json"); |
|
| 28 | 28 | return $jsonReader->readAndParse()['warehouse']; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | protected function execute(InputInterface $input, OutputInterface $output) |
| 49 | 49 | { |
| 50 | 50 | /** @var Warehouse $warehouse */ |
| 51 | - $warehouse = Warehouse::createFromJson(getcwd() . "/../resources/biggerWarehouse.json"); |
|
| 51 | + $warehouse = Warehouse::createFromJson(getcwd()."/../resources/biggerWarehouse.json"); |
|
| 52 | 52 | $calculatedArray = $warehouse->getPlaces(); |
| 53 | 53 | |
| 54 | 54 | $warehouse->setPathCalculator(new ShortPathCalculator()); |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | protected function execute(InputInterface $input, OutputInterface $output) |
| 38 | 38 | { |
| 39 | 39 | /** @var Warehouse $warehouse */ |
| 40 | - $warehouse = Warehouse::createFromJson(getcwd() . "/../resources/simpleWarehouse.json"); |
|
| 40 | + $warehouse = Warehouse::createFromJson(getcwd()."/../resources/simpleWarehouse.json"); |
|
| 41 | 41 | |
| 42 | 42 | $this->printTable($output, array(), $warehouse->createMatrix()); |
| 43 | 43 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public static function getMatrixSimple() |
| 25 | 25 | { |
| 26 | - $jsonReader = new JsonReader(getcwd() . "/../resources/biggerWarehouse.json"); |
|
| 26 | + $jsonReader = new JsonReader(getcwd()."/../resources/biggerWarehouse.json"); |
|
| 27 | 27 | return $jsonReader->readAndParse()['warehouse']; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | protected function execute(InputInterface $input, OutputInterface $output) |
| 48 | 48 | { |
| 49 | 49 | /** @var Warehouse $warehouse */ |
| 50 | - $warehouse = Warehouse::createFromJson(getcwd() . "/../resources/biggerWarehouse.json"); |
|
| 50 | + $warehouse = Warehouse::createFromJson(getcwd()."/../resources/biggerWarehouse.json"); |
|
| 51 | 51 | $calculatedArray = $warehouse->getPlaces(); |
| 52 | 52 | |
| 53 | 53 | $warehouse->setPathCalculator(new FastCalculator()); |
@@ -44,17 +44,17 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | public function parse() |
| 46 | 46 | { |
| 47 | - foreach($this->originalMatrix as $rKey => $row) { |
|
| 48 | - foreach($row as $cKey => $column) { |
|
| 47 | + foreach ($this->originalMatrix as $rKey => $row) { |
|
| 48 | + foreach ($row as $cKey => $column) { |
|
| 49 | 49 | $placeType = $this->placeCollector->getPlaceTypeByWeight($column['weight']); |
| 50 | 50 | $placeTypeNew = clone($placeType); |
| 51 | 51 | |
| 52 | - $placeTypeNew->setName($rKey . $cKey); |
|
| 53 | - if( isset($this->originalMatrix[$rKey - 1][$cKey]['obj']) ) { |
|
| 52 | + $placeTypeNew->setName($rKey.$cKey); |
|
| 53 | + if (isset($this->originalMatrix[$rKey - 1][$cKey]['obj'])) { |
|
| 54 | 54 | $placeTypeNew->setTopRef($this->originalMatrix[$rKey - 1][$cKey]['obj']); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if( isset($this->originalMatrix[$rKey][$cKey - 1]['obj']) ) { |
|
| 57 | + if (isset($this->originalMatrix[$rKey][$cKey - 1]['obj'])) { |
|
| 58 | 58 | $placeTypeNew->setLeftRef($this->originalMatrix[$rKey][$cKey - 1]['obj']); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -3,10 +3,10 @@ discard block |
||
| 3 | 3 | use GGGGino\WarehousePath\Tools\Console\ConsoleRunner; |
| 4 | 4 | use Symfony\Component\Console\Helper\HelperSet; |
| 5 | 5 | |
| 6 | -$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php']; |
|
| 6 | +$files = [__DIR__.'/../vendor/autoload.php', __DIR__.'/../../../autoload.php']; |
|
| 7 | 7 | $loader = null; |
| 8 | 8 | $cwd = getcwd(); |
| 9 | -$directories = [$cwd, $cwd . DIRECTORY_SEPARATOR . 'config']; |
|
| 9 | +$directories = [$cwd, $cwd.DIRECTORY_SEPARATOR.'config']; |
|
| 10 | 10 | $configFile = null; |
| 11 | 11 | |
| 12 | 12 | foreach ($files as $file) { |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | -if (! $loader) { |
|
| 20 | +if (!$loader) { |
|
| 21 | 21 | throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?'); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -$commands = []; |
|
| 24 | +$commands = []; |
|
| 25 | 25 | |
| 26 | 26 | ConsoleRunner::run($commands); |