src/Service/DbCleaner.php
private function strategy(callable $action)
    {
        $report = false;

        $tables = [
            'image' => Image::class,
            'resize' => Resize::class,
            'crop' => Crop::class
            ];

        foreach($tables as $type_name => $modelClass)
        {
            $wehave = $modelClass::all();

            foreach($wehave as $model)
            {
                $entity_name = $model->entity_name;

                if($type_name === 'image')
                {
                    $name = $model->name;
                }
                else
                {
                    $name = $model->image_name;
                }

                if(!$this->taxonomy->exist($entity_name))
                {
                    $action(1, $type_name, $model);
                    $report = true;
                }
                else
                {
                    $ownerType = $this->taxonomy->getType($entity_name);

                    if($ownerType->getRank() === TypeRank::OWN)
                    {
                        $action(2, $type_name, $model);
                        $report = true;
                    }
                    elseif(!$ownerType->ownExist($name))
                    {
                        $action(3, $type_name, $model);
                        $report = true;
                    }
                    elseif($ownerType->getFieldType($name)->getName() !== 'image')
                    {
                        $action(4, $type_name, $model);
                        $report = true;
                    }
                    elseif($type_name !== 'image')
                    {
                        $field = $ownerType->getField($name);

                        $imageSSet = $this->settingsSet->getImage($field);

                        if($type_name === 'resize')
                        {
                            if(!$imageSSet->resizeExist($model->name))
                            {
                                $action(5, $type_name, $model);
                                $report = true;
                            }
                        }
                        elseif($type_name === 'crop')
                        {
                            if(!$imageSSet->cropExist($model->name))
                            {
                                $action(5, $type_name, $model);
                                $report = true;
                            }
                        }
                    }
                }
            }
        }

        return $report;
    }
private function strategy(callable $action)
    {
        $report = false;

        $tables = [
            'image' => Image::class,
            'resize' => Resize::class,
            'crop' => Crop::class
            ];

        foreach($tables as $type_name => $modelClass)
        {
            $wehave = $modelClass::all();

            foreach($wehave as $model)
            {
                $entity_name = $model->entity_name;

                if($type_name === 'image')
                {
                    $name = $model->name;
                }
                else
                {
                    $name = $model->image_name;
                }

                if(!$this->taxonomy->exist($entity_name))
                {
                    $action(1, $type_name, $model);
                    $report = true;
                }
                else
                {
                    $ownerType = $this->taxonomy->getType($entity_name);

                    if($ownerType->getRank() === TypeRank::OWN)
                    {
                        $action(2, $type_name, $model);
                        $report = true;
                    }
                    elseif(!$ownerType->ownExist($name))
                    {
                        $action(3, $type_name, $model);
                        $report = true;
                    }
                    elseif($ownerType->getFieldType($name)->getName() !== 'image')
                    {
                        $action(4, $type_name, $model);
                        $report = true;
                    }
                    elseif($type_name !== 'image')
                    {
                        $field = $ownerType->getField($name);

                        $imageSSet = $this->settingsSet->getImage($field);

                        if($type_name === 'resize')
                        {
                            if(!$imageSSet->resizeExist($model->name))
                            {
                                $action(5, $type_name, $model);
                                $report = true;
                            }
                        }
                        elseif($type_name === 'crop')
                        {
                            if(!$imageSSet->cropExist($model->name))
                            {
                                $action(5, $type_name, $model);
                                $report = true;
                            }
                        }
                    }
                }
            }
        }

        return $report;
    }
@param callable $action

@return bool