We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 12 | 
| Paths | 73 | 
| Total Lines | 73 | 
| Code Lines | 42 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 57 | public function listAction()  | 
            ||
| 58 |     { | 
            ||
| 59 | $solr = Solr::getInstance($this->settings['solrcore']);  | 
            ||
| 60 | |||
| 61 |         if (!$solr->ready) { | 
            ||
| 62 |             $this->logger->error('Apache Solr not available'); | 
            ||
| 63 | return;  | 
            ||
| 64 | }  | 
            ||
| 65 | // We only care about the UID and partOf in the results and want them sorted  | 
            ||
| 66 | $params['fields'] = 'uid,partof';  | 
            ||
| 67 | $params['sort'] = ['uid' => 'asc'];  | 
            ||
| 68 | $collections = [];  | 
            ||
| 69 | |||
| 70 | // Sort collections according to order in plugin flexform configuration  | 
            ||
| 71 |         if ($this->settings['collections']) { | 
            ||
| 72 | $sortedCollections = [];  | 
            ||
| 73 |             foreach (GeneralUtility::intExplode(',', $this->settings['collections']) as $uid) { | 
            ||
| 74 | $sortedCollections[$uid] = $this->collectionRepository->findByUid($uid);  | 
            ||
| 75 | }  | 
            ||
| 76 | $collections = $sortedCollections;  | 
            ||
| 77 |         } else { | 
            ||
| 78 | $collections = $this->collectionRepository->findAll();  | 
            ||
| 79 | }  | 
            ||
| 80 | |||
| 81 |         if (count($collections) == 1 && empty($this->settings['dont_show_single'])) { | 
            ||
| 82 |             $this->forward('show', null, null, ['collection' => array_pop($collections)]); | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 83 | }  | 
            ||
| 84 | |||
| 85 | $processedCollections = [];  | 
            ||
| 86 | |||
| 87 | // Process results.  | 
            ||
| 88 |         foreach ($collections as $collection) { | 
            ||
| 89 | $solr_query = '';  | 
            ||
| 90 |             if ($collection->getIndexSearch() != '') { | 
            ||
| 91 |                 $solr_query .= '(' . $collection->getIndexSearch() . ')'; | 
            ||
| 92 |             } else { | 
            ||
| 93 |                 $solr_query .= 'collection:("' . Solr::escapeQuery($collection->getIndexName()) . '")'; | 
            ||
| 94 | }  | 
            ||
| 95 | $params['query'] = $solr_query . ' AND partof:0 AND toplevel:true';  | 
            ||
| 96 | $partOfNothing = $solr->search_raw($params);  | 
            ||
| 97 | |||
| 98 | $params['query'] = $solr_query . ' AND NOT partof:0 AND toplevel:true';  | 
            ||
| 99 | $partOfSomething = $solr->search_raw($params);  | 
            ||
| 100 | // Titles are all documents that are "root" elements i.e. partof == 0  | 
            ||
| 101 | $collectionInfo['titles'] = [];  | 
            ||
| 102 |             foreach ($partOfNothing as $doc) { | 
            ||
| 103 | $collectionInfo['titles'][$doc->uid] = $doc->uid;  | 
            ||
| 104 | }  | 
            ||
| 105 | // Volumes are documents that are both  | 
            ||
| 106 | // a) "leaf" elements i.e. partof != 0  | 
            ||
| 107 |             // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) | 
            ||
| 108 | $collectionInfo['volumes'] = $collectionInfo['titles'];  | 
            ||
| 109 |             foreach ($partOfSomething as $doc) { | 
            ||
| 110 | $collectionInfo['volumes'][$doc->uid] = $doc->uid;  | 
            ||
| 111 | // If a document is referenced via partof, it’s not a volume anymore.  | 
            ||
| 112 | unset($collectionInfo['volumes'][$doc->partof]);  | 
            ||
| 113 | }  | 
            ||
| 114 | |||
| 115 | // Generate random but unique array key taking priority into account.  | 
            ||
| 116 |             do { | 
            ||
| 117 | $_key = ($collectionInfo['priority'] * 1000) + mt_rand(0, 1000);  | 
            ||
| 118 | } while (!empty($processedCollections[$_key]));  | 
            ||
| 119 | |||
| 120 | $processedCollections[$_key]['collection'] = $collection;  | 
            ||
| 121 | $processedCollections[$_key]['info'] = $collectionInfo;  | 
            ||
| 122 | }  | 
            ||
| 123 | |||
| 124 | // Randomize sorting?  | 
            ||
| 125 |         if (!empty($this->settings['randomize'])) { | 
            ||
| 126 | ksort($processedCollections, SORT_NUMERIC);  | 
            ||
| 127 | }  | 
            ||
| 128 | |||
| 129 |         $this->view->assign('collections', $processedCollections); | 
            ||
| 130 | }  | 
            ||
| 205 |