Code Duplication    Length = 19-22 lines in 2 locations

source/Spiral/ODM/DocumentEntity.php 1 location

@@ 593-614 (lines=22) @@
590
     *
591
     * @throws DocumentException
592
     */
593
    protected function validate($reset = false)
594
    {
595
        $this->nestedErrors = [];
596
597
        //Validating all compositions
598
        foreach ($this->odmSchema[ODM::D_COMPOSITIONS] as $field) {
599
600
            $composition = $this->getField($field);
601
            if (!$composition instanceof ValidatesInterface) {
602
                //Something weird.
603
                continue;
604
            }
605
606
            if (!$composition->isValid()) {
607
                $this->nestedErrors[$field] = $composition->getErrors($reset);
608
            }
609
        }
610
611
        parent::validate($reset);
612
613
        return $this->hasErrors() && empty($this->nestedErrors);
614
    }
615
616
    /**
617
     * {@inheritdoc}

source/Spiral/ORM/RecordEntity.php 1 location

@@ 633-651 (lines=19) @@
630
     *
631
     * @throws RecordException
632
     */
633
    protected function validate($reset = false)
634
    {
635
        $this->nestedErrors = [];
636
637
        foreach ($this->relations as $name => $relation) {
638
            if (!$relation instanceof ValidatesInterface) {
639
                //Never constructed
640
                continue;
641
            }
642
643
            if ($this->embeddedRelation($name) && !$relation->isValid()) {
644
                $this->nestedErrors[$name] = $relation->getErrors($reset);
645
            }
646
        }
647
648
        parent::validate($reset);
649
650
        return $this->hasErrors() && empty($this->nestedErrors);
651
    }
652
653
    /**
654
     * Get WHERE array to be used to perform record data update or deletion. Usually will include