ValidateMessageImplementation::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2016 Billie Thompson
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace PurpleBooth\GitLintValidators;
13
14
use PurpleBooth\GitLintValidators\Validator\Validator;
15
16
/**
17
 * Validate against a number of validators against a message.
18
 */
19
class ValidateMessageImplementation implements ValidateMessage
20
{
21
    /**
22
     * @var array
23
     */
24
    private $validators;
25
26
    /**
27
     * ValidationServiceImplementation constructor.
28
     *
29
     * @param array $validators
30
     */
31
    public function __construct(array $validators)
32
    {
33
        $this->validators = $validators;
34
35
        if (count($validators) < 1) {
36
            new \LogicException('You need to provide the validation service with at least 1 validator');
37
        }
38
    }
39
40
    /**
41
     * Test a message against a number of validators.
42
     *
43
     * @param Message $message
44
     */
45
    public function validate(Message $message)
46
    {
47
        /** @var Validator $validator */
48
        foreach ($this->validators as $validator) {
49
            $validator->validate($message);
50
        }
51
    }
52
}
53