1 | <?php |
||
10 | * @author bootjp |
||
11 | */ |
||
12 | class Checker |
||
13 | { |
||
14 | protected $client; |
||
15 | |||
16 | protected static $ipAddress; |
||
17 | |||
18 | protected $error = ''; |
||
19 | |||
20 | public function __construct($iniFilePath = null) |
||
40 | |||
41 | /** |
||
42 | * @param string $url [optional] |
||
43 | * @return array |
||
44 | */ |
||
45 | public function fetch($url = 'http://support.sakura.ad.jp/mainte/mainteindex.php?service=vps') |
||
65 | |||
66 | /** |
||
67 | * @param string $contents |
||
68 | * @return array |
||
69 | */ |
||
70 | private function parse($contents) |
||
71 | { |
||
72 | preg_match_all('{(?<ipaddress>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)}s', $contents, $matches); |
||
73 | $onPageIpAddress = $matches['ipaddress']; |
||
74 | |||
75 | return array_reduce(array_keys(self::$ipAddress), function($carry, $checkType) use($onPageIpAddress) { |
||
76 | $result = array_filter(self::$ipAddress[$checkType], function($identifier) use($onPageIpAddress, $checkType) { |
||
77 | switch ($checkType) { |
||
78 | case 'static': |
||
79 | return in_array($identifier, $onPageIpAddress); |
||
80 | |||
81 | case 'regexp': |
||
82 | foreach ($onPageIpAddress as $ipAddress) { |
||
83 | if (preg_match($identifier, $ipAddress) === 1) { |
||
84 | return true; |
||
85 | } |
||
109 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.