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  | 
            ||
| 58 | public function listAction()  | 
            ||
| 59 |     { | 
            ||
| 60 | $solr = Solr::getInstance($this->settings['solrcore']);  | 
            ||
| 61 | |||
| 62 |         if (!$solr->ready) { | 
            ||
| 63 |             $this->logger->error('Apache Solr not available'); | 
            ||
| 64 | return;  | 
            ||
| 65 | }  | 
            ||
| 66 | // We only care about the UID and partOf in the results and want them sorted  | 
            ||
| 67 | $params['fields'] = 'uid,partof';  | 
            ||
| 68 | $params['sort'] = ['uid' => 'asc'];  | 
            ||
| 69 | $collections = [];  | 
            ||
| 70 | |||
| 71 | // Sort collections according to order in plugin flexform configuration  | 
            ||
| 72 |         if ($this->settings['collections']) { | 
            ||
| 73 | $sortedCollections = [];  | 
            ||
| 74 |             foreach (GeneralUtility::intExplode(',', $this->settings['collections']) as $uid) { | 
            ||
| 75 | $sortedCollections[$uid] = $this->collectionRepository->findByUid($uid);  | 
            ||
| 76 | }  | 
            ||
| 77 | $collections = $sortedCollections;  | 
            ||
| 78 |         } else { | 
            ||
| 79 | $collections = $this->collectionRepository->findAll();  | 
            ||
| 80 | }  | 
            ||
| 81 | |||
| 82 |         if (count($collections) == 1 && empty($this->settings['dont_show_single'])) { | 
            ||
| 83 |             $this->forward('show', null, null, ['collection' => array_pop($collections)]); | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 84 | }  | 
            ||
| 85 | |||
| 86 | $processedCollections = [];  | 
            ||
| 87 | |||
| 88 | // Process results.  | 
            ||
| 89 |         foreach ($collections as $collection) { | 
            ||
| 90 | $solr_query = '';  | 
            ||
| 91 |             if ($collection->getIndexSearch() != '') { | 
            ||
| 92 |                 $solr_query .= '(' . $collection->getIndexSearch() . ')'; | 
            ||
| 93 |             } else { | 
            ||
| 94 |                 $solr_query .= 'collection:("' . Solr::escapeQuery($collection->getIndexName()) . '")'; | 
            ||
| 95 | }  | 
            ||
| 96 | $params['query'] = $solr_query . ' AND partof:0 AND toplevel:true';  | 
            ||
| 97 | $partOfNothing = $solr->search_raw($params);  | 
            ||
| 98 | |||
| 99 | $params['query'] = $solr_query . ' AND NOT partof:0 AND toplevel:true';  | 
            ||
| 100 | $partOfSomething = $solr->search_raw($params);  | 
            ||
| 101 | // Titles are all documents that are "root" elements i.e. partof == 0  | 
            ||
| 102 | $collectionInfo['titles'] = [];  | 
            ||
| 103 |             foreach ($partOfNothing as $doc) { | 
            ||
| 104 | $collectionInfo['titles'][$doc->uid] = $doc->uid;  | 
            ||
| 105 | }  | 
            ||
| 106 | // Volumes are documents that are both  | 
            ||
| 107 | // a) "leaf" elements i.e. partof != 0  | 
            ||
| 108 |             // b) "root" elements that are not referenced by other documents ("root" elements that have no descendants) | 
            ||
| 109 | $collectionInfo['volumes'] = $collectionInfo['titles'];  | 
            ||
| 110 |             foreach ($partOfSomething as $doc) { | 
            ||
| 111 | $collectionInfo['volumes'][$doc->uid] = $doc->uid;  | 
            ||
| 112 | // If a document is referenced via partof, it’s not a volume anymore.  | 
            ||
| 113 | unset($collectionInfo['volumes'][$doc->partof]);  | 
            ||
| 114 | }  | 
            ||
| 115 | |||
| 116 | // Generate random but unique array key taking priority into account.  | 
            ||
| 117 |             do { | 
            ||
| 118 | $_key = ($collectionInfo['priority'] * 1000) + mt_rand(0, 1000);  | 
            ||
| 119 | } while (!empty($processedCollections[$_key]));  | 
            ||
| 120 | |||
| 121 | $processedCollections[$_key]['collection'] = $collection;  | 
            ||
| 122 | $processedCollections[$_key]['info'] = $collectionInfo;  | 
            ||
| 123 | }  | 
            ||
| 124 | |||
| 125 | // Randomize sorting?  | 
            ||
| 126 |         if (!empty($this->settings['randomize'])) { | 
            ||
| 127 | ksort($processedCollections, SORT_NUMERIC);  | 
            ||
| 128 | }  | 
            ||
| 129 | |||
| 130 |         $this->view->assign('collections', $processedCollections); | 
            ||
| 131 | }  | 
            ||
| 206 |