TypeHandlingTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 4
c 3
b 1
f 0
dl 0
loc 47
ccs 6
cts 6
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A typeCheck() 0 3 1
A expectType() 0 3 1
A typeCast() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved\IteratorPipeline\Traits;
6
7
use Improved as i;
8
9
/**
10
 * Type handling methods for iterator pipeline.
11
 */
12
trait TypeHandlingTrait
13
{
14
    /**
15
     * Define the next step via a callback that returns an array or Traversable object.
16
     *
17
     * @param callable $callback
18
     * @param mixed    ...$args
19
     * @return static
20
     */
21
    abstract public function then(callable $callback, ...$args);
22
23
24
    /**
25
     * Validate that a value has a specific type.
26
     * @deprecated
27
     *
28
     * @param string|string[]        $type
29
     * @param string|\Throwable|null $error
30
     * @return static
31
     */
32 4
    public function expectType($type, $error = null)
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::expectType() return type has no value type specified in iterable type static(Improved\IteratorPipeline\Pipeline).
Loading history...
33
    {
34 4
        return $this->then("Improved\iterable_expect_type", $type, $error);
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::expectType() should return static(Improved\IteratorPipeline\Pipeline) but returns Improved\IteratorPipeline\Pipeline.
Loading history...
35
    }
36
37
    /**
38
     * Validate that a value has a specific type.
39
     *
40
     * @param string|string[] $type
41
     * @param \Throwable|null $throwable
42
     * @return static
43
     */
44 3
    public function typeCheck($type, ?\Throwable $throwable = null)
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::typeCheck() return type has no value type specified in iterable type static(Improved\IteratorPipeline\Pipeline).
Loading history...
45
    {
46 3
        return $this->then("Improved\iterable_type_check", $type, $throwable);
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::typeCheck() should return static(Improved\IteratorPipeline\Pipeline) but returns Improved\IteratorPipeline\Pipeline.
Loading history...
47
    }
48
49
    /**
50
     * Cast a value to the specific type or throw an error.
51
     *
52
     * @param string          $type
53
     * @param \Throwable|null $throwable
54
     * @return static
55
     */
56 3
    public function typeCast(string $type, ?\Throwable $throwable = null)
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::typeCast() return type has no value type specified in iterable type static(Improved\IteratorPipeline\Pipeline).
Loading history...
57
    {
58 3
        return $this->then("Improved\iterable_type_cast", $type, $throwable);
0 ignored issues
show
introduced by
Method Improved\IteratorPipeline\Pipeline::typeCast() should return static(Improved\IteratorPipeline\Pipeline) but returns Improved\IteratorPipeline\Pipeline.
Loading history...
59
    }
60
}
61