Skip to content

Commit 5661f60

Browse files
committed
Improve PHPDoc, add InvalidArgumentException for preSize
1 parent 7b55ab9 commit 5661f60

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/DiamondAndSquare.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ class DiamondAndSquare
1515
{
1616

1717
/**
18+
* Real size (computed in the generate() method)
1819
*
1920
* @var int
2021
*/
2122
private $size;
2223

23-
private $terra = array(array());
24+
/**
25+
* @var SplFixedArray
26+
*/
27+
private $terra;
2428

2529
/**
2630
*
@@ -43,6 +47,10 @@ public function __construct()
4347
*/
4448
public function generate($preSize, $offset = null)
4549
{
50+
if (!is_int($preSize)) {
51+
throw new InvalidArgumentException(sprintf("preSize must be int, %s given", gettype($preSize)));
52+
}
53+
4654
$this->size = pow(2, $preSize) + 1;
4755
$this->setMaxOffset($offset);
4856

@@ -62,11 +70,20 @@ public function generate($preSize, $offset = null)
6270
return $this;
6371
}
6472

73+
/**
74+
* @return SplFixedArray
75+
*/
6576
public function getMap()
6677
{
6778
return $this->terra;
6879
}
6980

81+
/**
82+
* @param int $size
83+
* @param int|float $maxOffset
84+
*
85+
* @return SplFixedArray
86+
*/
7087
public static function generateAndGetMap($size, $maxOffset = null)
7188
{
7289
$map = new self();
@@ -167,13 +184,15 @@ private function getMaxOffset()
167184
*/
168185
private function setMaxOffset($maxOffset)
169186
{
170-
if(!is_numeric($maxOffset))
171-
throw new InvalidArgumentException("maxOffset must be numeric");
187+
if (!is_numeric($maxOffset)) {
188+
throw new InvalidArgumentException(sprintf("maxOffset must be numeric, %s given", gettype($maxOffset)));
189+
}
172190

173-
if($maxOffset === null)
191+
if ($maxOffset === null) {
174192
$maxOffset = $this->size;
175-
elseif($maxOffset == 0)
193+
} elseif ($maxOffset == 0) {
176194
throw new InvalidArgumentException("maxOffset should not be equal 0");
195+
}
177196

178197
$this->maxOffset = abs($maxOffset);
179198
}

0 commit comments

Comments
 (0)