| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | class Wikipedia | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |     const URL = 'https://en.wikipedia.org/w/api.php?action=query&titles=Microsoft_Edge&prop=revisions&rvprop=content&rvsection=4&format=xml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     private static $errors = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |         'fetch_error' => 'Unable to fetch content', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |         'parse_error' => 'Unable to parse content', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |     public static function fetch() | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |         $content = file_get_contents(self::URL); | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |         if (!$content) throw new Exception(self::$errors['fetch_error']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |         $content = explode('===Release history===', $content); | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |         if (!isset($content[1])) throw new Exception(self::$errors['parse_error']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |         $table = explode('|-', $content[1]); | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         if (!isset($table[1])) throw new Exception(self::$errors['parse_error']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |         $table = array_slice($table, 1); | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         $versions = array_map(array('Wikipedia', 'extractVersion'), $table); | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         self::writeEdgeVersions($versions); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private static function extractVersion($content) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $lines = array_slice(array_filter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             explode(PHP_EOL, $content), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             function ($val) { return trim($val) && strpos($val, '|') === 0; } | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         ), 0, 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         preg_match("/{[^}{]*Version[^}{]*\| ?([\d\.]+)}/", $lines[0], $edgeVersion); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         preg_match("/\| *(\d*\.\d*)/", $lines[1], $edgeHtmlVersion); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         if (!isset($edgeVersion[1])) throw new Exception(self::$errors['parse_error']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         if (!isset($edgeHtmlVersion[1])) throw new Exception(self::$errors['parse_error']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         return array($edgeHtmlVersion[1], $edgeVersion[1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 41 |  | View Code Duplication |     private static function writeEdgeVersions($versions) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $file = __DIR__ . '/../../src/edgeVersionMap.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $currentVersions = require $file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         foreach ($versions as $version) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $currentVersions[$version[0]] = $version[1]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         ksort($currentVersions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $content = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         foreach ($currentVersions as $edgeHtml => $edge) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $content .= "    '{$edgeHtml}' => '{$edge}'," . PHP_EOL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $data = <<<PHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     %s | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | PHP; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         file_put_contents($file, sprintf($data, trim($content))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.