Completed
Push — master ( 6f962e...549eec )
by Kamil
21:17
created

NotificationChecker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 52
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A checkNotification() 0 13 3
A hasType() 0 4 1
A hasMessage() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Behat\Service;
13
14
use Sylius\Behat\Exception\NotificationExpectationMismatchException;
15
use Sylius\Behat\NotificationType;
16
use Sylius\Behat\Service\Accessor\NotificationAccessorInterface;
17
18
/**
19
 * @author Łukasz Chruściel <[email protected]>
20
 * @author Arkadiusz Krakowiak <[email protected]>
21
 */
22
final class NotificationChecker implements NotificationCheckerInterface
23
{
24
    /**
25
     * @var NotificationAccessorInterface
26
     */
27
    private $notificationAccessor;
28
29
    /**
30
     * @param NotificationAccessorInterface $notificationAccessor
31
     */
32
    public function __construct(NotificationAccessorInterface $notificationAccessor)
33
    {
34
        $this->notificationAccessor = $notificationAccessor;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function checkNotification($message, NotificationType $type)
41
    {
42
        if ($this->hasType($type) && $this->hasMessage($message)) {
43
            return;
44
        }
45
46
        throw new NotificationExpectationMismatchException(
47
            $type,
48
            $message,
49
            $this->notificationAccessor->getType(),
50
            $this->notificationAccessor->getMessage()
51
        );
52
    }
53
54
    /**
55
     * @param NotificationType $type
56
     *
57
     * @return bool
58
     */
59
    private function hasType(NotificationType $type)
60
    {
61
        return $type === $this->notificationAccessor->getType();
62
    }
63
64
    /**
65
     * @param string $message
66
     *
67
     * @return bool
68
     */
69
    private function hasMessage($message)
70
    {
71
        return false !== strpos($this->notificationAccessor->getMessage(), $message);
72
    }
73
}
74