JsonSchemaAdapter::getData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Adapter for JsonSchema library https://github.com/justinrainbow/json-schema
4
 *
5
 * @file      JsonSchemaAdapter.php
6
 *
7
 * PHP version 8.0+
8
 *
9
 * @author    Yancharuk Alexander <alex at itvault dot info>
10
 * @copyright © 2012-2021 Alexander Yancharuk <alex at itvault at info>
11
 * @date      2017-01-17 14:54
12
 * @license   The BSD 3-Clause License
13
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
14
 */
15
16
namespace Veles\Request\Validator\Adapters;
17
18
use Traits\DriverInterface;
19
use Veles\Request\Validator\ValidatorInterface;
20
use Veles\Traits\Driver;
21
22
/**
23
 * Class   JsonSchemaAdapter
24
 *
25
 * @author Yancharuk Alexander <alex at itvault at info>
26
 */
27
class JsonSchemaAdapter implements ValidatorInterface, DriverInterface
28
{
29
	use Driver;
30
31
	protected $resolver;
32
33 5
	public function __construct($driver, $resolver)
34
	{
35 5
		$this->driver   = $driver;
36 5
		$this->resolver = $resolver;
37
	}
38
39
	/**
40
	 * Add error
41
	 *
42
	 * @param array $error
43
	 */
44 1
	public function addError(array $error)
45
	{
46 1
		$field = $message = '';
47 1
		extract($error, EXTR_IF_EXISTS);
48
49 1
		$this->driver->addError($field, $message);
50
	}
51
52
	/**
53
	 * Get error array
54
	 *
55
	 * @return array
56
	 */
57 1
	public function getErrors()
58
	{
59 1
		return $this->driver->getErrors();
60
	}
61
62
	/**
63
	 * Validate data
64
	 *
65
	 * @param mixed $data
66
	 * @param mixed $definitions
67
	 */
68 1
	public function check($data, $definitions)
69
	{
70
		/** @noinspection PhpUndefinedMethodInspection */
71 1
		$this->resolver->resolve($definitions);
72
73 1
		$this->driver->check($data, $definitions);
74
	}
75
76
	/**
77
	 * Check validation result
78
	 *
79
	 * @return bool
80
	 */
81 1
	public function isValid()
82
	{
83 1
		return $this->driver->isValid();
84
	}
85
86
	/**
87
	 * Method not used. Just a stub
88
	 *
89
	 * @codeCoverageIgnore
90
	 */
91
	public function getData()
92
	{
93
	}
94
}
95