Code Duplication    Length = 21-24 lines in 2 locations

source/Spiral/ORM/RecordEntity.php 1 location

@@ 817-840 (lines=24) @@
814
     *
815
     * Will validate every loaded and embedded relation.
816
     */
817
    protected function validate($reset = false)
818
    {
819
        $this->nestedErrors = [];
820
821
        //Validating all compositions/accessors
822
        foreach ($this->fields as $field => $value) {
823
            //Ensuring value state
824
            $value = $this->getField($field);
825
            if (!$value instanceof ValidatesInterface) {
826
                continue;
827
            }
828
829
            if (!$value->isValid()) {
830
                $this->nestedErrors[$field] = $value->getErrors($reset);
831
            }
832
        }
833
834
        //We have to validate some relations before saving them
835
        $this->validateRelations($reset);
836
837
        parent::validate($reset);
838
839
        return empty($this->errors + $this->nestedErrors);
840
    }
841
842
    /**
843
     * {@inheritdoc}

source/Spiral/ODM/DocumentEntity.php 1 location

@@ 628-648 (lines=21) @@
625
     * @param bool $reset
626
     * @throws DocumentException
627
     */
628
    protected function validate($reset = false)
629
    {
630
        $this->nestedErrors = [];
631
632
        //Validating all compositions
633
        foreach ($this->odmSchema[ODM::D_COMPOSITIONS] as $field) {
634
            $composition = $this->getField($field);
635
            if (!$composition instanceof CompositableInterface) {
636
                //Something weird.
637
                continue;
638
            }
639
640
            if (!$composition->isValid()) {
641
                $this->nestedErrors[$field] = $composition->getErrors($reset);
642
            }
643
        }
644
645
        parent::validate($reset);
646
647
        return empty($this->errors + $this->nestedErrors);
648
    }
649
650
    /**
651
     * {@inheritdoc}