ActionCollection::hasAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Cysha\Casino\Holdem\Game;
4
5
use Illuminate\Support\Collection;
6
7
class ActionCollection extends Collection
8
{
9
    public function all()
10
    {
11
        return $this
12
            ->map(function (Action $action) {
13
                return $action->toString();
14
            })
15
            ->toArray();
16
    }
17
18
    /**
19
     * @param int $actionValue
20
     *
21
     * @return bool
22
     */
23
    public function hasAction(int $actionValue): bool
24
    {
25
        $count = $this
26
            ->filter(function (Action $action) use ($actionValue) {
27
                return $action->action() === $actionValue;
28
            })
29
            ->count();
30
31
        return $count > 0 ? true : false;
32
    }
33
}
34