Code Duplication    Length = 23-25 lines in 2 locations

models/Product.php 2 locations

@@ 375-399 (lines=25) @@
372
     * @throws \October\Rain\Database\ModelException
373
     * @return void
374
     */
375
    protected function validateInventories()
376
    {
377
        if (! is_array($this->optionsInventories) ||
378
            ! is_array($this->optionsInventories['options'])) {
379
            return;
380
        }
381
382
        $takenValueCombinations = [];
383
        foreach ($this->optionsInventories['inventories'] as $inventory) {
384
            // validate the inventory
385
            $model = new Inventory($inventory);
386
            $model->validate();
387
388
            // validate that the value combinations are unique
389
            sort($inventory['valueIds']);
390
            $valueCombination = json_encode($inventory['valueIds']);
391
392
            if (in_array($valueCombination, $takenValueCombinations)) {
393
                Flash::error(Lang::get('bedard.shop::lang.products.form.duplicate_inventories_error'));
394
                throw new ModelException($this);
395
            }
396
397
            $takenValueCombinations[] = $valueCombination;
398
        }
399
    }
400
401
    /**
402
     * Validate options.
@@ 407-429 (lines=23) @@
404
     * @throws \October\Rain\Database\ModelException
405
     * @return void
406
     */
407
    protected function validateOptions()
408
    {
409
        if (! is_array($this->optionsInventories) ||
410
            ! is_array($this->optionsInventories['options'])) {
411
            return;
412
        }
413
414
        $names = [];
415
        foreach ($this->optionsInventories['options'] as $option) {
416
            $name = strtolower(trim($option['name']));
417
            // validate the option
418
            $model = new Option($option);
419
            $model->validate();
420
421
            // validate that names are unique
422
            if (in_array($name, $names)) {
423
                Flash::error(Lang::get('bedard.shop::lang.products.form.duplicate_options_error'));
424
                throw new ModelException($this);
425
            }
426
427
            $names[] = $name;
428
        }
429
    }
430
}
431