Skip to content

Commit 07cb012

Browse files
committed
Renamed complex types.
1 parent e4faff8 commit 07cb012

File tree

7 files changed

+27
-23
lines changed

7 files changed

+27
-23
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Table of Contents
77
=================
88
* [General usage](#general-usage)
99
- [1. Simple signature](#simple-signature)
10-
- [2. Conjoined types](#conjoined-types)
11-
- [3. Disjoined types](#disjoined-types)
10+
- [2. Union types](#union-types)
11+
- [3. Intersection types](#intersection-types)
1212
- [4. Optional parameters](#optional-parameters)
1313

1414
<a name="General usage"></a>
@@ -33,9 +33,9 @@ Parameters signature is a list of types separeted by comma.
3333
var_dump($func('1', '1')) // => '11'
3434
```
3535

36-
<a name="conjoined-types"></a>
36+
<a name="union-types"></a>
3737

38-
### 2. Conjoined types:
38+
### 2. Union types:
3939

4040
Sometimes your parameter need to be of a kind, that implements not one interface, but several.
4141

@@ -47,9 +47,9 @@ Sometimes your parameter need to be of a kind, that implements not one interface
4747
var_dump($func(new ArrayIterator)) // => bool(true)
4848
```
4949

50-
<a name="disjoined-types"></a>
50+
<a name="intersection-types"></a>
5151

52-
### 3. Disjoined types:
52+
### 3. Intersection types:
5353

5454
Sometimes you allow parameter to be not of one type, but of several types.
5555

bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<?php
22

33
$loader = require __DIR__ . '/vendor/autoload.php';
4+

src/Signature/Signature.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
namespace Sevavietl\OverloadedFunction\Signature;
44

55
use Sevavietl\OverloadedFunction\Signature\Types\Type;
6-
use Sevavietl\OverloadedFunction\Signature\Types\DisjoinedType;
7-
use Sevavietl\OverloadedFunction\Signature\Types\ConjoinedType;
6+
use Sevavietl\OverloadedFunction\Signature\Types\UnionType;
7+
use Sevavietl\OverloadedFunction\Signature\Types\IntersectionType;
88
use Sevavietl\OverloadedFunction\Signature\Types\OptionalType;
99

1010
class Signature
1111
{
12+
const UNION_TYPE_SEPARATOR = '|';
13+
const INTERSECTION_TYPE_SEPARATOR = '&';
14+
1215
private $types;
1316

1417
public function __construct($stringRepresentation)
@@ -25,10 +28,10 @@ private function parseStringRepresentation($stringRepresentation)
2528
$paramType = substr($paramType, 1);
2629
}
2730

28-
if ($this->isDisjoined($paramType)) {
29-
$type = new DisjoinedType(explode('|', $paramType));
30-
} elseif ($this->isConjoined($paramType)) {
31-
$type = new ConjoinedType(explode('&', $paramType));
31+
if ($this->isUnion($paramType)) {
32+
$type = new UnionType(explode(self::UNION_TYPE_SEPARATOR, $paramType));
33+
} elseif ($this->isIntersection($paramType)) {
34+
$type = new IntersectionType(explode(self::INTERSECTION_TYPE_SEPARATOR, $paramType));
3235
} else {
3336
$type = new Type($paramType);
3437
}
@@ -42,14 +45,14 @@ private function isOptional($paramType)
4245
return strpos($paramType, '?') === 0;
4346
}
4447

45-
private function isDisjoined($paramType)
48+
private function isUnion($paramType)
4649
{
47-
return strpos($paramType, '|') !== false;
50+
return strpos($paramType, self::UNION_TYPE_SEPARATOR) !== false;
4851
}
4952

50-
private function isConjoined($paramType)
53+
private function isIntersection($paramType)
5154
{
52-
return strpos($paramType, '&') !== false;
55+
return strpos($paramType, self::INTERSECTION_TYPE_SEPARATOR) !== false;
5356
}
5457

5558
public function match(array $params)

src/Signature/Types/ConjoinedType.php renamed to src/Signature/Types/IntersectionType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Sevavietl\OverloadedFunction\Signature\Types;
44

5-
class ConjoinedType implements IType
5+
class IntersectionType implements IType
66
{
77
private $types;
88

src/Signature/Types/DisjoinedType.php renamed to src/Signature/Types/UnionType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Sevavietl\OverloadedFunction\Signature\Types;
44

5-
class DisjoinedType implements IType
5+
class UnionType implements IType
66
{
77
private $types;
88

tests/unit/Signature/Types/ConjoinedTypeTest.php renamed to tests/unit/Signature/Types/IntersectionTypeTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
namespace Sevavietl\OverloadedFunction\Tests\Unit\Signature\Types;
44

5-
use Sevavietl\OverloadedFunction\Signature\Types\ConjoinedType;
5+
use Sevavietl\OverloadedFunction\Signature\Types\IntersectionType;
66

7-
class ConjoinedTypeTest extends \TestCase
7+
class IntersectionTypeTest extends \TestCase
88
{
99
/**
1010
* @dataProvider matchDataProvider
1111
*/
1212
public function testMatch($typeStrings, $param, $result)
1313
{
14-
$this->assertEquals($result, (new ConjoinedType($typeStrings))->match($param));
14+
$this->assertEquals($result, (new IntersectionType($typeStrings))->match($param));
1515
}
1616

1717
public function matchDataProvider()

tests/unit/Signature/Types/DisjoinedTypeTest.php renamed to tests/unit/Signature/Types/UnionTypeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Sevavietl\OverloadedFunction\Tests\Unit\Signature\Types;
44

5-
use Sevavietl\OverloadedFunction\Signature\Types\DisjoinedType;
5+
use Sevavietl\OverloadedFunction\Signature\Types\UnionType;
66

77
class DisjoinedTypeTest extends \TestCase
88
{
@@ -11,7 +11,7 @@ class DisjoinedTypeTest extends \TestCase
1111
*/
1212
public function testMatch($typeStrings, $param, $result)
1313
{
14-
$this->assertEquals($result, (new DisjoinedType($typeStrings))->match($param));
14+
$this->assertEquals($result, (new UnionType($typeStrings))->match($param));
1515
}
1616

1717
public function matchDataProvider()

0 commit comments

Comments
 (0)