<commit_before><?php

namespace Stevebauman\Maintenance\Controllers\Inventory;

use Stevebauman\Maintenance\Validators\InventoryValidator;
use Stevebauman\Maintenance\Services\Inventory\InventoryService;
use Stevebauman\Maintenance\Controllers\BaseController;

/**
 * Class InventoryController.
 */
class InventoryController extends BaseController
{
    /**
     * @var InventoryService
     */
    protected $inventory;

    /**
     * @var InventoryValidator
     */
    protected $inventoryValidator;

    /**
     * @param InventoryService   $inventory
     * @param InventoryValidator $inventoryValidator
     */
    public function __construct(InventoryService $inventory, InventoryValidator $inventoryValidator)
    {
        $this->inventory = $inventory;
        $this->inventoryValidator = $inventoryValidator;
    }

    /**
     * Display all inventory entries (paginated with search functionality).
     *
     * @return mixed
     */
    public function index()
    {
        $items = $this->inventory->setInput($this->inputAll())->getByPageWithFilter();

        return view('maintenance::inventory.index', [
            'title' => 'Inventory',
            'items' => $items,
        ]);
    }

    /**
     * Show the form for creating an inventory.
     *
     * @return mixed
     */
    public function create()
    {
        return view('maintenance::inventory.create', [
            'title' => 'Add an Item to the Inventory',
        ]);
    }

    /**
     * Store a new inventory.
     *
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function store()
    {
        $this->inventoryValidator->unique('name', $this->inventory->getTableName(), 'name');

        if ($this->inventoryValidator->passes()) {
            $record = $this->inventory->setInput($this->inputAll())->create();

            if ($record) {
                $this->message = sprintf('Successfully added item to the inventory: %s', link_to_route('maintenance.inventory.show', 'Show', [$record->id]));
                $this->messageType = 'success';
                $this->redirect = route('maintenance.inventory.index');
            } else {
                $this->message = 'There was an error adding this item to the inventory. Please try again.';
                $this->messageType = 'danger';
                $this->redirect = route('maintenance.inventory.create');
            }
        } else {
            $this->errors = $this->inventoryValidator->getErrors();
        }

        return $this->response();
    }

    /**
     * Display the specified inventory.
     *
     * @param $id
     *
     * @return mixed
     */
    public function show($id)
    {
        $item = $this->inventory->find($id);

        return view('maintenance::inventory.show', [
            'title' => 'Viewing Inventory Item: '.$item->name,
            'item' => $item,
        ]);
    }

    /**
     * Displays the edit form for the specified inventory.
     *
     * @param $id
     *
     * @return mixed
     */
    public function edit($id)
    {
        $item = $this->inventory->find($id);

        return view('maintenance::inventory.edit', [
            'title' => 'Editing Inventory Item: '.$item->name,
            'item' => $item,
        ]);
    }

    /**
     * Updates the specified inventory.
     *
     * @param $id
     *
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function update($id)
    {
        $this->inventoryValidator->ignore('name', $this->inventory->getTableName(), 'name', $id);

        if ($this->inventoryValidator->passes()) {
            $item = $this->inventory->setInput($this->inputAll())->update($id);

            if ($item) {
                $this->message = sprintf('Successfully updated item: %s', link_to_route('maintenance.inventory.show', 'Show', [$item->id]));
                $this->messageType = 'success';
                $this->redirect = route('maintenance.inventory.show', [$item->id]);
            } else {
                $this->message = 'There was an error trying to update this item. Please try again.';
                $this->messageType = 'danger';
                $this->redirect = route('maintenance.inventory.edit', [$id]);
            }
        } else {
            $this->errors = $this->inventoryValidator->getErrors();
        }

        return $this->response();
    }

    /**
     * Removes the specified inventory.
     *
     * @param $id
     *
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function destroy($id)
    {<commit_msg>Remove unique naming validation on inventory items<commit_after><?php

namespace Stevebauman\Maintenance\Controllers\Inventory;

use Stevebauman\Maintenance\Validators\InventoryValidator;
use Stevebauman\Maintenance\Services\Inventory\InventoryService;
use Stevebauman\Maintenance\Controllers\BaseController;

/**
 * Class InventoryController.
 */
class InventoryController extends BaseController
{
    /**
     * @var InventoryService
     */
    protected $inventory;

    /**
     * @var InventoryValidator
     */
    protected $inventoryValidator;

    /**
     * @param InventoryService   $inventory
     * @param InventoryValidator $inventoryValidator
     */
    public function __construct(InventoryService $inventory, InventoryValidator $inventoryValidator)
    {
        $this->inventory = $inventory;
        $this->inventoryValidator = $inventoryValidator;
    }

    /**
     * Display all inventory entries (paginated with search functionality).
     *
     * @return mixed
     */
    public function index()
    {
        $items = $this->inventory->setInput($this->inputAll())->getByPageWithFilter();

        return view('maintenance::inventory.index', [
            'title' => 'Inventory',
            'items' => $items,
        ]);
    }

    /**
     * Show the form for creating an inventory.
     *
     * @return mixed
     */
    public function create()
    {
        return view('maintenance::inventory.create', [
            'title' => 'Add an Item to the Inventory',
        ]);
    }

    /**
     * Store a new inventory.
     *
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function store()
    {
        if ($this->inventoryValidator->passes()) {
            $record = $this->inventory->setInput($this->inputAll())->create();

            if ($record) {
                $this->message = sprintf('Successfully added item to the inventory: %s', link_to_route('maintenance.inventory.show', 'Show', [$record->id]));
                $this->messageType = 'success';
                $this->redirect = route('maintenance.inventory.index');
            } else {
                $this->message = 'There was an error adding this item to the inventory. Please try again.';
                $this->messageType = 'danger';
                $this->redirect = route('maintenance.inventory.create');
            }
        } else {
            $this->errors = $this->inventoryValidator->getErrors();
        }

        return $this->response();
    }

    /**
     * Display the specified inventory.
     *
     * @param $id
     *
     * @return mixed
     */
    public function show($id)
    {
        $item = $this->inventory->find($id);

        return view('maintenance::inventory.show', [
            'title' => 'Viewing Inventory Item: '.$item->name,
            'item' => $item,
        ]);
    }

    /**
     * Displays the edit form for the specified inventory.
     *
     * @param $id
     *
     * @return mixed
     */
    public function edit($id)
    {
        $item = $this->inventory->find($id);

        return view('maintenance::inventory.edit', [
            'title' => 'Editing Inventory Item: '.$item->name,
            'item' => $item,
        ]);
    }

    /**
     * Updates the specified inventory.
     *
     * @param $id
     *
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function update($id)
    {
        if ($this->inventoryValidator->passes()) {
            $item = $this->inventory->setInput($this->inputAll())->update($id);

            if ($item) {
                $this->message = sprintf('Successfully updated item: %s', link_to_route('maintenance.inventory.show', 'Show', [$item->id]));
                $this->messageType = 'success';
                $this->redirect = route('maintenance.inventory.show', [$item->id]);
            } else {
                $this->message = 'There was an error trying to update this item. Please try again.';
                $this->messageType = 'danger';
                $this->redirect = route('maintenance.inventory.edit', [$id]);
            }
        } else {
            $this->errors = $this->inventoryValidator->getErrors();
        }

        return $this->response();
    }

    /**
     * Removes the specified inventory.
     *
     * @param $id
     *
     * @return \Illuminate\Http\JsonResponse|mixed
     */
    public function destroy($id)
    {
{'fraction_non_alphanumeric': 0.143144260830728, 'fraction_numerical': 0.0, 'mean_word_length': 2.080123796423659, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 119, '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': '420567', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2435, 'n_words': 509}