Skip to content

Commit ccadbfc

Browse files
committed
Added isArray function
1 parent dbb90ec commit ccadbfc

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

src/TypeFunctions.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ function isResource($variable)
8585
return is_resource($variable);
8686
}
8787

88+
/**
89+
* @param mixed $variable
90+
*
91+
* @return bool
92+
*/
93+
function isArray($variable)
94+
{
95+
return is_array($variable);
96+
}
97+
8898
/**
8999
* @param mixed $variable
90100
*
@@ -93,14 +103,15 @@ function isResource($variable)
93103
function getType($variable)
94104
{
95105
$functions = [
96-
"isNumber" => "number",
97-
"isBoolean" => "boolean",
98-
"isNull" => "null",
99-
"isObject" => "object",
100-
"isFunction" => "function",
106+
"isNumber" => "number",
107+
"isBoolean" => "boolean",
108+
"isNull" => "null",
109+
"isObject" => "object",
110+
"isFunction" => "function",
101111
"isExpression" => "expression",
102-
"isString" => "string",
103-
"isResource" => "resource"
112+
"isString" => "string",
113+
"isResource" => "resource",
114+
"isArray" => "array"
104115
];
105116

106117
$result = "unknown";

tests/Test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66

77
class Test extends PHPUnit_Framework_TestCase
88
{
9-
109
}

tests/TypeFunctionTest.php

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TypeFunctionTest extends Test
99
/**
1010
* @test
1111
*/
12-
public function testIsNumber()
12+
public function itIdentifiesNumbers()
1313
{
1414
$this->assertTrue(TypeFunctions\isNumber(0));
1515
$this->assertTrue(TypeFunctions\isNumber(0.5));
@@ -23,7 +23,7 @@ public function testIsNumber()
2323
/**
2424
* @test
2525
*/
26-
public function testIsBoolean()
26+
public function itIdentifiesBooleans()
2727
{
2828
$this->assertTrue(TypeFunctions\isBoolean(true));
2929
$this->assertTrue(TypeFunctions\isBoolean(false));
@@ -37,7 +37,7 @@ public function testIsBoolean()
3737
/**
3838
* @test
3939
*/
40-
public function testIsNull()
40+
public function itIdentifiesNulls()
4141
{
4242
$this->assertTrue(TypeFunctions\isNull(null));
4343

@@ -49,7 +49,7 @@ public function testIsNull()
4949
/**
5050
* @test
5151
*/
52-
public function testIsObject()
52+
public function itIdentifiesObjects()
5353
{
5454
$this->assertTrue(TypeFunctions\isObject($this));
5555

@@ -63,7 +63,7 @@ public function testIsObject()
6363
/**
6464
* @test
6565
*/
66-
public function testIsFunction()
66+
public function itIdentifiesFunctions()
6767
{
6868
$function = function () {
6969
echo "hello";
@@ -78,7 +78,7 @@ public function testIsFunction()
7878
/**
7979
* @test
8080
*/
81-
public function testIsExpression()
81+
public function itIdentifiesExpressions()
8282
{
8383
$this->assertTrue(TypeFunctions\isExpression("[a-z]"));
8484

@@ -88,7 +88,7 @@ public function testIsExpression()
8888
/**
8989
* @test
9090
*/
91-
public function testIsString()
91+
public function itIdentifiesStrings()
9292
{
9393
$this->assertTrue(TypeFunctions\isString("hello"));
9494

@@ -98,7 +98,7 @@ public function testIsString()
9898
/**
9999
* @test
100100
*/
101-
public function testIsResource()
101+
public function itIdentifiesResources()
102102
{
103103
$file = fopen(__FILE__, "r");
104104

@@ -112,7 +112,17 @@ public function testIsResource()
112112
/**
113113
* @test
114114
*/
115-
public function testGetType()
115+
public function itIdentifiesArrays()
116+
{
117+
$this->assertTrue(TypeFunctions\isArray(["foo", "bar"]));
118+
119+
$this->assertFalse(TypeFunctions\isArray("foo"));
120+
}
121+
122+
/**
123+
* @test
124+
*/
125+
public function itIdentifiesTypes()
116126
{
117127
$file = fopen(__FILE__, "r");
118128

@@ -121,14 +131,15 @@ public function testGetType()
121131
};
122132

123133
$types = [
124-
"number" => 1.5,
125-
"boolean" => true,
126-
"null" => null,
127-
"object" => $this,
128-
"function" => $function,
134+
"number" => 1.5,
135+
"boolean" => true,
136+
"null" => null,
137+
"object" => $this,
138+
"function" => $function,
129139
"expression" => "[a-z]",
130-
"string" => "hello",
131-
"resource" => $file
140+
"string" => "hello",
141+
"resource" => $file,
142+
"array" => ["foo", "bar"]
132143
];
133144

134145
foreach ($types as $type => $variable) {

0 commit comments

Comments
 (0)