FormData   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 2
cbo 0
dl 0
loc 77
ccs 18
cts 19
cp 0.9474
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A getMethod() 0 3 1
A isMethod() 0 3 1
A has() 0 3 1
A get() 0 3 2
A getData() 0 3 1
1
<?php
2
3
4
  namespace Fiv\Form;
5
6
  /**
7
   * @author Vitaly Sevastyanov
8
   */
9
  class FormData {
10
11
    CONST METHOD_GET = 'GET';
12
13
    CONST METHOD_POST = 'POST';
14
15
    /**
16
     * @var string
17
     */
18
    protected $method;
19
20
    /**
21
     * @var array
22
     */
23
    protected $data;
24
25
26
    /**
27
     * @param string $method
28
     * @param array $data
29
     */
30 35
    public function __construct($method, array $data = []) {
31 35
      if (!is_string($method)) {
32
        throw new \InvalidArgumentException('Parameter "method" should be a string,  ' . gettype($method) . ' given.');
33
      }
34 35
      $method = strtoupper($method);
35 35
      if (!in_array($method, [self::METHOD_GET, self::METHOD_POST])) {
36 1
        throw new \InvalidArgumentException('Invalid http method name.');
37
      }
38 34
      $this->method = $method;
39 34
      $this->data = $data;
40 34
    }
41
42
43
    /**
44
     * @return string
45
     */
46 1
    public function getMethod() {
47 1
      return $this->method;
48
    }
49
50
51
    /**
52
     * @param string $method
53
     * @return bool
54
     */
55 28
    public function isMethod($method) {
56 28
      return $this->method === strtoupper($method);
57
    }
58
59
60
    /**
61
     * @param string $name
62
     * @return bool
63
     */
64 29
    public function has($name) {
65 29
      return isset($this->data[$name]);
66
    }
67
68
69
    /**
70
     * @param string $name
71
     * @return mixed|null
72
     */
73 24
    public function get($name) {
74 24
      return isset($this->data[$name]) ? $this->data[$name] : null;
75
    }
76
77
78
    /**
79
     * @return array
80
     */
81 1
    public function getData() {
82 1
      return $this->data;
83
    }
84
85
  }