StringTrait::validateString()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 5
nc 4
nop 3
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
1
<?php namespace CMPayments\SchemaValidator\Validators;
2
3
use CMPayments\SchemaValidator\Exceptions\ValidateException;
4
5
/**
6
 * Class StringTrait
7
 *
8
 * @package CMPayments\SchemaValidator\Validators
9
 * @Author  Boy Wijnmaalen <[email protected]>
10
 */
11
trait StringTrait
12
{
13
    /**
14
     * Validates a string to a Schema
15
     *
16
     * @param $data
17
     * @param $schema
18
     * @param $path
19
     */
20
    public function validateString($data, $schema, $path)
21
    {
22
        // check for $schema->minLength
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
        if (isset($schema->minLength) && (($currentLength = strlen($data)) < $schema->minLength)) {
24
25
            $this->addError(ValidateException::ERROR_USER_STRING_MINIMUM_CHECK, [$path, $schema->minLength, $data, $currentLength]);
26
        }
27
28
        // check for $schema->maxLength
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
        if (isset($schema->maxLength) && (($currentLength = strlen($data)) > $schema->maxLength)) {
30
31
            $this->addError(ValidateException::ERROR_USER_STRING_MAXIMUM_CHECK, [$path, $schema->maxLength, $data, $currentLength]);
32
        }
33
    }
34
35
    /**
36
     * @param int   $code
37
     * @param array $args
38
     *
39
     * @return mixed
40
     */
41
    abstract public function addError($code, array $args = []);
42
}