| Total Complexity | 11 |
| Total Lines | 105 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class HeaderItem |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * 头部名 |
||
| 12 | * |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $name; |
||
| 16 | /** |
||
| 17 | * 头部值 |
||
| 18 | * |
||
| 19 | * @var mixed |
||
| 20 | */ |
||
| 21 | protected $value; |
||
| 22 | |||
| 23 | public function __construct(string $name, string $value) |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * 从 $_SERVER 变量获取 |
||
| 32 | * |
||
| 33 | * @param array $server |
||
| 34 | * @return HeaderItem[] 头部数组 |
||
| 35 | */ |
||
| 36 | public static function buildFromServer(array $server):array |
||
| 37 | { |
||
| 38 | $headers = []; |
||
| 39 | foreach ($server as $key => $value) { |
||
| 40 | if (strpos($key, 'HTTP_') === 0) { |
||
| 41 | $name = substr($key, strlen('HTTP_')); |
||
| 42 | $headers[$name] = $value; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * 获取头部信息 |
||
| 49 | * |
||
| 50 | * @param array $headers |
||
| 51 | * @return HeaderItem[] |
||
| 52 | */ |
||
| 53 | public static function build(array $headers):array |
||
| 54 | { |
||
| 55 | $build = []; |
||
| 56 | foreach ($headers as $name => $value) { |
||
| 57 | if ($value instanceof HeaderItem) { |
||
| 58 | $header = $value; |
||
| 59 | } else { |
||
| 60 | $header = new HeaderItem($name, $value); |
||
| 61 | } |
||
| 62 | $build[$header->getName()] = $header; |
||
| 63 | } |
||
| 64 | return $build; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get 头部名 |
||
| 69 | * |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | public function getName() |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Set 头部名 |
||
| 79 | * |
||
| 80 | * @param string $name 头部名 |
||
| 81 | * |
||
| 82 | * @return self |
||
| 83 | */ |
||
| 84 | public function setName(string $name) |
||
| 85 | { |
||
| 86 | $this->name = $name; |
||
| 87 | |||
| 88 | return $this; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Get 头部值 |
||
| 93 | * |
||
| 94 | * @return mixed |
||
| 95 | */ |
||
| 96 | public function getValue() |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Set 头部值 |
||
| 103 | * |
||
| 104 | * @param mixed $value 头部值 |
||
| 105 | * |
||
| 106 | * @return self |
||
| 107 | */ |
||
| 108 | public function setValue($value) |
||
| 113 | } |
||
| 114 | } |
||
| 115 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.