Completed
Push — master ( f02f00...968d20 )
by Rick
03:07
created

IsString   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 39
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
A shouldBreakChainOnError() 0 4 1
1
<?php
2
/**
3
 * Particle.
4
 *
5
 * @link      http://github.com/particle-php for the canonical source repository
6
 * @copyright Copyright (c) 2005-2016 Particle (http://particle-php.com)
7
 * @license   https://github.com/particle-php/validator/blob/master/LICENSE New BSD License
8
 */
9
namespace Particle\Validator\Rule;
10
11
use Particle\Validator\Rule;
12
13
/**
14
 * This rule is for validating if a value represents a string.
15
 *
16
 * @package Particle\Validator\Rule
17
 */
18
class IsString extends Rule
19
{
20
    /**
21
     * A constant that will be used when the value does not represent a string.
22
     */
23
    const NOT_A_STRING = 'IsString::NOT_A_STRING';
24
25
    /**
26
     * The message templates which can be returned by this validator.
27
     *
28
     * @var array
29
     */
30
    protected $messageTemplates = [
31
        self::NOT_A_STRING => '{{ name }} must be a string',
32
    ];
33
34
    /**
35
     * Validates if $value represents a string.
36
     *
37
     * @param mixed $value
38
     * @return bool
39
     */
40 7
    public function validate($value)
41
    {
42 7
        if (is_string($value)) {
43 2
            return true;
44
        }
45
46 5
        return $this->error(self::NOT_A_STRING);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 5
    public function shouldBreakChainOnError()
53
    {
54 5
        return true;
55
    }
56
}
57