JsonValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validateValue() 0 8 2
1
<?php
2
3
namespace hiapi\validators;
4
5
use yii\base\InvalidArgumentException;
6
use yii\helpers\Json;
7
use yii\validators\Validator;
8
9
/**
10
 * Class JsonValidator
11
 *
12
 * @author Dmytro Naumenko <[email protected]>
13
 */
14
class JsonValidator extends Validator
15
{
16
    public function __construct(array $config = [])
17
    {
18
        parent::__construct($config);
19
20
        $this->message = '{attribute} must be a valid JSON';
21
    }
22
23
    protected function validateValue($value)
24
    {
25
        try {
26
            Json::decode($value);
27
        } catch (InvalidArgumentException $e) {
0 ignored issues
show
Bug introduced by
The class yii\base\InvalidArgumentException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
28
            return [$this->message, []];
29
        }
30
    }
31
}
32