Util::provideItemsOfSupportedTypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phive\Queue\Tests\Queue;
13
14
use Phive\Queue\Queue;
15
16
trait Util
17
{
18
    /**
19
     * @return \PHPUnit_Framework_MockObject_MockObject
20
     */
21
    public function getQueueMock()
22
    {
23
        return $this->getMock('Phive\Queue\Queue');
0 ignored issues
show
Bug introduced by
It seems like getMock() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
24
    }
25
26
    public function provideQueueInterfaceMethods()
27
    {
28
        return array_chunk(get_class_methods('Phive\Queue\Queue'), 1);
29
    }
30
31
    public function callQueueMethod(Queue $queue, $method)
32
    {
33
        $r = new \ReflectionMethod($queue, $method);
34
35
        if ($num = $r->getNumberOfRequiredParameters()) {
36
            return call_user_func_array([$queue, $method], array_fill(0, $num, 'foo'));
37
        }
38
39
        return $queue->$method();
40
    }
41
42
    public function provideItemsOfVariousTypes()
43
    {
44
        $data = [];
45
46
        foreach (Types::getAll() as $type => $item) {
47
            $data[$type] = [$item, $type];
48
        }
49
50
        return $data;
51
    }
52
53
    public function provideItemsOfSupportedTypes()
54
    {
55
        return array_diff_key(
56
            $this->provideItemsOfVariousTypes(),
57
            array_fill_keys($this->getUnsupportedItemTypes(), false)
58
        );
59
    }
60
61
    public function provideItemsOfUnsupportedTypes()
62
    {
63
        return array_intersect_key(
64
            $this->provideItemsOfVariousTypes(),
65
            array_fill_keys($this->getUnsupportedItemTypes(), false)
66
        );
67
    }
68
69
    protected function getUnsupportedItemTypes()
70
    {
71
        return [];
72
    }
73
}
74