diff --git a/.idea/coffeetable.iml b/.idea/coffeetable.iml
index fe3b477..0f8e83f 100644
--- a/.idea/coffeetable.iml
+++ b/.idea/coffeetable.iml
@@ -4,7 +4,6 @@
-
@@ -35,6 +34,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -97,15 +108,5 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ed54236..23e3b59 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,8 +5,13 @@
+
+
+
+
+
@@ -35,8 +40,8 @@
-
-
+
+
@@ -45,8 +50,8 @@
-
-
+
+
@@ -55,7 +60,7 @@
-
+
@@ -75,8 +80,8 @@
-
-
+
+
@@ -92,6 +97,16 @@
+
+
+
+
+
+
+
+
+
+
@@ -147,14 +162,14 @@
-
-
+
+
@@ -169,33 +184,33 @@
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
-
+
-
-
-
-
-
-
+
@@ -462,14 +477,7 @@
-
-
-
- 1458150506101
-
-
-
- 1458150506101
+
1458154532845
@@ -807,16 +815,17 @@
1458825316172
-
+
+ 1458825420827
+
+
+
+ 1458825420827
+
+
-
-
-
-
-
-
@@ -841,9 +850,15 @@
+
+
+
+
+
+
-
+
@@ -865,7 +880,7 @@
-
+
@@ -937,7 +952,7 @@
file://$PROJECT_DIR$/src/Coffee/Table.php
- 139
+ 153
@@ -1213,14 +1228,6 @@
-
-
-
-
-
-
-
-
@@ -1229,14 +1236,6 @@
-
-
-
-
-
-
-
-
@@ -1311,7 +1310,7 @@
-
+
@@ -1319,16 +1318,32 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
diff --git a/composer.lock b/composer.lock
index f2729cb..20f96c8 100644
--- a/composer.lock
+++ b/composer.lock
@@ -637,16 +637,16 @@
},
{
"name": "phpunit/phpunit-mock-objects",
- "version": "3.0.6",
+ "version": "3.1.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
- "reference": "49bc700750196c04dd6bc2c4c99cb632b893836b"
+ "reference": "7c34c9bdde4131b824086457a3145e27dba10ca1"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/49bc700750196c04dd6bc2c4c99cb632b893836b",
- "reference": "49bc700750196c04dd6bc2c4c99cb632b893836b",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/7c34c9bdde4131b824086457a3145e27dba10ca1",
+ "reference": "7c34c9bdde4131b824086457a3145e27dba10ca1",
"shasum": ""
},
"require": {
@@ -664,7 +664,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.0.x-dev"
+ "dev-master": "3.1.x-dev"
}
},
"autoload": {
@@ -689,7 +689,7 @@
"mock",
"xunit"
],
- "time": "2015-12-08 08:47:06"
+ "time": "2016-03-24 05:58:25"
},
{
"name": "sebastian/code-unit-reverse-lookup",
diff --git a/index.php b/index.php
index 17a80c3..66e3556 100644
--- a/index.php
+++ b/index.php
@@ -2,6 +2,7 @@
namespace Coffee;
+// If 'vendor/' folder does not exist, please run 'composer install'
require __DIR__ . '/vendor/autoload.php';
try {
@@ -58,14 +59,14 @@ try {
echo '' . "\n";
/** @var Tile $tile */
foreach ($tileRow as $tile) {
- $spotNumber = 0;
- $attribute = '';
- if (!is_null($tile->getSpot())) {
- $spotNumber = $tile->getSpot()->getNumber();
+ $attribute = '';
+ if ($tile->isRepresentingSpot()) {
$attribute = ' class="coffee"';
}
+ $spotNumber = $tile->getSpot()->getNumber();
+
echo '' . $spotNumber . ' | ' . "\n";
}
echo '
' . "\n";
@@ -73,6 +74,7 @@ try {
echo '' . "\n";
echo '' . "\n";
+ // TODO: introduce i18n/pluralism
echo 'Najväčšia kávová kaluž je s číslom ';
$numbers = '';
$delimiter = ', ';
@@ -86,6 +88,7 @@ try {
}
catch (\Exception $e) {
// TODO: provide more information, like the file:line for example
+ echo '' . "\n";
echo 'Caught exception: ' . $e->getMessage() . "\n";
}
diff --git a/src/Coffee/Spot.php b/src/Coffee/Spot.php
index 7eef87a..7e1c570 100644
--- a/src/Coffee/Spot.php
+++ b/src/Coffee/Spot.php
@@ -8,11 +8,11 @@
namespace Coffee;
-/**
- * Class Spot
- *
- * @package Coffee
- */
+ /**
+ * Class Spot
+ *
+ * @package Coffee
+ */
/**
* Class Spot
*
@@ -35,8 +35,10 @@ class Spot {
*
* @param Tile $tile
*/
- public function __construct(Tile $tile) {
- $this->addTile($tile);
+ public function __construct(Tile $tile = null) {
+ if (!is_null($tile)) {
+ $this->addTile($tile);
+ }
}
/**
diff --git a/src/Coffee/Table.php b/src/Coffee/Table.php
index 0de33f9..0da9761 100644
--- a/src/Coffee/Table.php
+++ b/src/Coffee/Table.php
@@ -9,16 +9,26 @@ namespace Coffee;
*/
class Table extends Map {
+ /**
+ * Since spot numbering starts from 1, 0 is a good candidate
+ */
+ const VOID_SPOT_NUMBER = 0;
+
/**
* @var Spot[]
*/
private $spots = [];
/**
- * @var Spot
+ * @var Spot|null
*/
private $currentSpot = null;
+ /**
+ * @var Spot|null
+ */
+ private $voidSpot = null;
+
/**
* @var Spot[]
*/
@@ -37,6 +47,8 @@ class Table extends Map {
public function __construct($description) {
parent::__construct($description);
+ $this->voidSpot = new Spot();
+ $this->voidSpot->setNumber(self::VOID_SPOT_NUMBER);
$this->tileStack = new Stack();
$this->tileStack->push(array_reverse($this->getTiles()));
@@ -48,6 +60,7 @@ class Table extends Map {
if ($tile->isRepresentingVoid()) {
$tile->visit();
$this->finishCurrentSpot();
+ $this->voidSpot->addTile($tile);
continue;
}
@@ -87,9 +100,14 @@ class Table extends Map {
/**
* @return Spot[]
+ * @throws \Exception
*/
public
function getLargestSpots() {
+ if (empty($this->largestSpots)) {
+ throw new \Exception('There are no spots in this table.');
+ }
+
return $this->largestSpots;
}
@@ -97,11 +115,7 @@ class Table extends Map {
* @return Spot
*/
public function getFirstLargestSpot() {
- if (empty($this->largestSpots)) {
- return null;
- }
-
- return $this->largestSpots[0];
+ return $this->getLargestSpots()[0];
}
/**
diff --git a/src/Coffee/Tile.php b/src/Coffee/Tile.php
index d6837c0..7913256 100644
--- a/src/Coffee/Tile.php
+++ b/src/Coffee/Tile.php
@@ -64,8 +64,13 @@ class Tile extends Position {
/**
* @return Spot
+ * @throws \Exception
*/
public function getSpot() {
+ if (is_null($this->spot)) {
+ throw new \Exception('This tile does not belong to any spot.');
+ }
+
return $this->spot;
}
@@ -104,5 +109,4 @@ class Tile extends Position {
return $this->representation == self::REPRESENTS_VOID;
}
-
}
\ No newline at end of file