| Conditions | 9 |
| Paths | 64 |
| Total Lines | 130 |
| Code Lines | 100 |
| 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 |
||
| 29 | public function run($request) |
||
| 30 | { |
||
| 31 | $this->extend('beforePopulate'); |
||
| 32 | |||
| 33 | $factory = Injector::inst()->create(FixtureFactory::class); |
||
| 34 | |||
| 35 | $parentid = 0; |
||
| 36 | |||
| 37 | $fixtureDir = realpath(__DIR__ . '/../../tests/php/Fixtures'); |
||
| 38 | |||
| 39 | //create products |
||
| 40 | if (!Product::get()->count()) { |
||
| 41 | $fixture = YamlFixture::create($fixtureDir . '/dummyproducts.yml'); |
||
| 42 | $fixture->writeInto($factory);//needs to be a data model |
||
| 43 | |||
| 44 | $shoppage = ProductCategory::get()->filter('URLSegment', 'shop')->first(); |
||
| 45 | $parentid = $shoppage->ID; |
||
| 46 | |||
| 47 | $categoriestopublish = [ |
||
| 48 | 'products', |
||
| 49 | 'electronics', |
||
| 50 | 'apparel', |
||
| 51 | 'entertainment', |
||
| 52 | 'music', |
||
| 53 | 'movies', |
||
| 54 | 'drama', |
||
| 55 | 'toys', |
||
| 56 | 'food', |
||
| 57 | 'books', |
||
| 58 | 'jewellery', |
||
| 59 | 'furniture', |
||
| 60 | 'kitchen', |
||
| 61 | 'bedroom', |
||
| 62 | 'stationery', |
||
| 63 | ]; |
||
| 64 | foreach ($categoriestopublish as $categoryname) { |
||
| 65 | $factory->get(ProductCategory::class, $categoryname)->publishSingle(); |
||
| 66 | } |
||
| 67 | $productstopublish = [ |
||
| 68 | 'mp3player', |
||
| 69 | 'hdtv', |
||
| 70 | 'socks', |
||
| 71 | 'tshirt', |
||
| 72 | 'beachball', |
||
| 73 | 'hoop', |
||
| 74 | 'kite', |
||
| 75 | 'genericmovie', |
||
| 76 | 'lemonchicken', |
||
| 77 | 'ring', |
||
| 78 | 'book', |
||
| 79 | 'lamp', |
||
| 80 | 'paper', |
||
| 81 | 'pens', |
||
| 82 | ]; |
||
| 83 | foreach ($productstopublish as $productname) { |
||
| 84 | $factory->get(Product::class, $productname)->publishSingle(); |
||
| 85 | } |
||
| 86 | DB::alteration_message('Created dummy products and categories', 'created'); |
||
| 87 | } else { |
||
| 88 | echo '<p style="color:orange;">Products and categories were not created because some already exist.</p>'; |
||
| 89 | } |
||
| 90 | |||
| 91 | //cart page |
||
| 92 | if (!CartPage::get()->first()) { |
||
| 93 | $fixture = YamlFixture::create($fixtureDir . '/pages/Cart.yml'); |
||
| 94 | $fixture->writeInto($factory); |
||
| 95 | $page = $factory->get(CartPage::class, 'cart'); |
||
| 96 | $page->ParentID = $parentid; |
||
| 97 | $page->writeToStage('Stage'); |
||
| 98 | $page->publishSingle(); |
||
| 99 | DB::alteration_message('Cart page created', 'created'); |
||
| 100 | } |
||
| 101 | |||
| 102 | //checkout page |
||
| 103 | if (!CheckoutPage::get()->first()) { |
||
| 104 | $fixture = YamlFixture::create($fixtureDir . '/pages/Checkout.yml'); |
||
| 105 | $fixture->writeInto($factory); |
||
| 106 | $page = $factory->get(CheckoutPage::class, 'checkout'); |
||
| 107 | $page->ParentID = $parentid; |
||
| 108 | $page->writeToStage('Stage'); |
||
| 109 | $page->publishSingle(); |
||
| 110 | DB::alteration_message('Checkout page created', 'created'); |
||
| 111 | } |
||
| 112 | |||
| 113 | //account page |
||
| 114 | if (!AccountPage::get()->first()) { |
||
| 115 | $fixture = YamlFixture::create($fixtureDir . '/pages/Account.yml'); |
||
| 116 | $fixture->writeInto($factory); |
||
| 117 | $page = $factory->get(AccountPage::class, 'account'); |
||
| 118 | $page->ParentID = $parentid; |
||
| 119 | $page->writeToStage('Stage'); |
||
| 120 | $page->publishSingle(); |
||
| 121 | DB::alteration_message('Account page \'Account\' created', 'created'); |
||
| 122 | } |
||
| 123 | |||
| 124 | //terms page |
||
| 125 | if (!Page::get()->filter('URLSegment', 'terms-and-conditions')->first()) { |
||
| 126 | $fixture = YamlFixture::create($fixtureDir . '/pages/TermsConditions.yml'); |
||
| 127 | $fixture->writeInto($factory); |
||
| 128 | $page = $factory->get('Page', 'termsconditions'); |
||
| 129 | $page->ParentID = $parentid; |
||
| 130 | $page->writeToStage('Stage'); |
||
| 131 | $page->publishSingle(); |
||
| 132 | //set terms page id in config |
||
| 133 | $config = SiteConfig::current_site_config(); |
||
| 134 | $config->TermsPageID = $page->ID; |
||
| 135 | $config->write(); |
||
| 136 | DB::alteration_message('Terms and conditions page created', 'created'); |
||
| 137 | } |
||
| 138 | |||
| 139 | //countries config - removes some countries |
||
| 140 | $siteconfig = SiteConfig::current_site_config(); |
||
| 141 | if (empty($siteconfig->AllowedCountries)) { |
||
| 142 | $siteconfig->AllowedCountries = |
||
| 143 | 'AF,AL,DZ,AS,AD,AO,AG,AR,AM,AU,AT,AZ,BS,BH, |
||
| 144 | BD,BB,BY,BE,BZ,BJ,BT,BO,BA,BW,BR,BN,BG,BF,BI, |
||
| 145 | KH,CM,CA,CV,CF,TD,CL,CN,CO,KM,CG,CR,CI,HR,CU, |
||
| 146 | CY,CZ,DK,DJ,DM,DO,EC,EG,SV,GQ,ER,EE,ET,FJ,FI, |
||
| 147 | FR,GA,GM,GE,DE,GH,GR,GD,GT,GN,GW,GY,HT,HN,HK, |
||
| 148 | HU,IS,IN,ID,IR,IQ,IE,IL,IT,JM,JP,JO,KZ,KE,KI, |
||
| 149 | KP,KR,KW,KG,LA,LV,LB,LS,LR,LY,LI,LT,LU,MG,MW, |
||
| 150 | MY,MV,ML,MT,MH,MR,MU,MX,FM,MD,MC,MN,MS,MA,MZ, |
||
| 151 | MM,NA,NR,NP,NL,NZ,NI,NE,NG,NO,OM,PK,PW,PA,PG, |
||
| 152 | PY,PE,PH,PL,PT,QA,RO,RU,RW,KN,LC,VC,WS,SM,ST, |
||
| 153 | SA,SN,SC,SL,SG,SK,SI,SB,SO,ZA,ES,LK,SD,SR,SZ, |
||
| 154 | SE,CH,SY,TJ,TZ,TH,TG,TO,TT,TN,TR,TM,TV,UG,UA, |
||
| 155 | AE,GB,US,UY,UZ,VU,VE,VN,YE,YU,ZM,ZW'; |
||
| 156 | $siteconfig->write(); |
||
| 157 | } |
||
| 158 | $this->extend('afterPopulate'); |
||
| 159 | } |
||
| 161 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths