| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Sportic\Timing\RaceTecClient\Parsers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use DOMElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Sportic\Timing\CommonClient\Models\Split; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Class ResultPage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @package Sportic\Timing\RaceTecClient\Parsers | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class ResultPage extends AbstractParser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     protected $returnContent = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     protected function generateContent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->returnContent['full_name'] = $this->parseFullName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->returnContent['time']      = $this->parseFinishTime(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->parsePositions(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->parseResultBio(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->returnContent['splits'] = $this->parseSplits(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         return $this->returnContent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function getModelClassName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         // TODO: Implement getModelClassName() method. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     protected function parseFullName() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         return trim( | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             $this->getCrawler()->filter('#ctl00_Content_Main_lblName')->text() | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     protected function parseFinishTime() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return trim( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             $this->getCrawler()->filter('#ctl00_Content_Main_lblResFinishTime')->text() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     protected function parsePositions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $posGenData = $this->getCrawler()->filter('#ctl00_Content_Main_lblResOPos')->text(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         list($posGen, $participants) = explode('/', $posGenData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->returnContent['pos_gen'] = trim($posGen); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->returnContent['race']['participants'] = trim($participants); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $posGenData = $this->getCrawler()->filter('#ctl00_Content_Main_lblResGPos')->text(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         list($posGen, $participants) = explode('/', $posGenData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $this->returnContent['pos_gender'] = trim($posGen); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->returnContent['gender']['participants'] = trim($participants); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $posGenData = $this->getCrawler()->filter('#ctl00_Content_Main_lblResCPos')->text(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         list($posGen, $participants) = explode('/', $posGenData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->returnContent['pos_category'] = trim($posGen); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->returnContent['category']['participants'] = trim($participants); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     protected function parseResultBio() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $table = $this->getCrawler()->filter('#ctl00_Content_Main_grdBio'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $rows = $table->filter('tbody > tr'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         foreach ($rows as $row) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             $indexCount = $row->childNodes->length; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             $column = $row->childNodes->item($indexCount-4)->nodeValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $value = $row->childNodes->item($indexCount-2)->nodeValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             switch ($column) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 case 'Race No': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                     $this->returnContent['bib'] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 case 'Gender': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                     $this->returnContent['gender']['name'] = ($value == 'Female' ? 'female' : 'male'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 case 'Category': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                     $this->returnContent['category']['name'] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 case 'Status': | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                     $this->returnContent['status']['name'] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     protected function parseSplits() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $return     = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $headerData = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $splitRows  = $this->getCrawler()->filter( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             '#ctl00_Content_Main_grdSplits_DXMainTable > tbody > tr' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         if ($splitRows->count() > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             foreach ($splitRows as $resultRow) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                 if ($resultRow->getAttribute('id') === 'ctl00_Content_Main_grdSplits_DXHeadersRow') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                     $headerData = $this->parseSplitsHeader($resultRow); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                     $result = $this->parseSplitRow($resultRow, $headerData); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                     if ($result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                         $return[] = $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * @param DOMElement $row | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     protected function parseSplitsHeader($row) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $return = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $fieldMap = self::getLabelMaps(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $colNum   = 0; | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 137 |  | View Code Duplication |         foreach ($row->childNodes as $node) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |             if ($node instanceof DOMElement) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                 $fieldName = trim($node->nodeValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                 $labelFind = array_search($fieldName, $fieldMap); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |                 if ($labelFind) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                     $return[$colNum] = $labelFind; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 $colNum++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         return $return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |      * @param $row | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      * @param $headerData | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |      * @return Split|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 157 |  | View Code Duplication |     protected function parseSplitRow($row, $headerData) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         $parameters = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         $i          = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         foreach ($row->childNodes as $cell) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             if ($cell instanceof DOMElement) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                 $parameters = $this->parseSplitCell($i, $cell, $headerData, $parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                 $i++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         if (count($parameters)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             return new Split($parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * @param $colCount | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * @param $cell | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * @param $headerData | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @param $parameters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     protected function parseSplitCell($colCount, $cell, $headerData, $parameters) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         if (isset($headerData[$colCount])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |             $field              = $headerData[$colCount]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             $parameters[$field] = trim($cell->nodeValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         return $parameters; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |     protected static function getLabelMaps() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             'name' => 'Split Name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |             'timeFromStart' => 'Time', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             'time' => 'Time From Previous Split', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 203 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 204 |  |  |  | 
            
                        
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.