<commit_before><?php

namespace LaravelEnso\Core\app\Classes\StructureManager;

use LaravelEnso\Core\app\Models\Menu;
use LaravelEnso\Core\app\Models\Permission;
use LaravelEnso\Core\app\Models\PermissionsGroup;

class StructureDestroyer
{
    private $permissionsGroup;
    private $permissions;
    private $menu;

    public function destroy()
    {
        \DB::transaction(function () {
            if ($this->permissions && $this->permissions->count()) {
                $this->permissions->each->delete();
            }

            if ($this->permissionsGroup) {
                if (!$this->permissionsGroup->permissions->count()) {
                    $this->permissionsGroup->delete();
                }
            }

            if ($this->menu) {
                $this->menu->delete();
            }
        });
    }

    public function setPermissionsGroup($permissionsGroup)
    {
        $this->permissionsGroup = PermissionsGroup::whereName($permissionsGroup['name'])->first();
    }

    public function setPermissions($permissions)
    {
        $this->permissions = collect();

        foreach ($permissions as $permission) {
            $this->permissions->push(Permission::whereName($permission['name'])->first());
        }
    }

    public function setMenu($menu)
    {
        $this->menu = new Menu($menu);
    }
}<commit_msg>fixed menu deletion in StructureDestroyer<commit_after><?php

namespace LaravelEnso\Core\app\Classes\StructureManager;

use LaravelEnso\Core\app\Models\Menu;
use LaravelEnso\Core\app\Models\Permission;
use LaravelEnso\Core\app\Models\PermissionsGroup;

class StructureDestroyer
{
    private $permissionsGroup;
    private $permissions;
    private $menu;

    public function destroy()
    {
        \DB::transaction(function () {
            if ($this->permissions && $this->permissions->count()) {
                $this->permissions->each->delete();
            }

            if ($this->permissionsGroup) {
                if (!$this->permissionsGroup->permissions->count()) {
                    $this->permissionsGroup->delete();
                }
            }

            if ($this->menu) {
                $this->menu->delete();
            }
        });
    }

    public function setPermissionsGroup($permissionsGroup)
    {
        $this->permissionsGroup = PermissionsGroup::whereName($permissionsGroup['name'])->first();
    }

    public function setPermissions($permissions)
    {
        $this->permissions = collect();

        foreach ($permissions as $permission) {
            $this->permissions->push(Permission::whereName($permission['name'])->first());
        }
    }

    public function setMenu($menu)
    {
        $this->menu = Menu::whereName($menu['name'])->first();
    }
}
{'fraction_non_alphanumeric': 0.1427536231884058, 'fraction_numerical': 0.0, 'mean_word_length': 2.322503008423586, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6739917', 'n_tokens_mistral': 760, 'n_tokens_neox': 740, 'n_words': 111}