<commit_before><?php

namespace Expressly\Provider;

use Expressly\Entity\Merchant;
use Silex\Application;

class MerchantProvider implements MerchantProviderInterface
{
    private $db;
    private $logger;
    private $table;
    private $merchant;

    public function __construct(Application $app)
    {
        $this->db = $app['db'];
        $this->logger = $app['logger'];
        $this->table = $app['config']['table']['merchant'];
        $this->merchant = $this->firstOrCreate();
    }

    private function firstOrCreate()
    {
        $merchant = new Merchant();

        try {
            $getQuery = sprintf('SELECT * FROM %s LIMIT 1', $this->table);
            $statement = $this->db->prepare($getQuery);
            $statement->execute();

            $result = $statement->fetch(\PDO::FETCH_ASSOC);

            if (empty($result)) {
                $merchant->setPassword();
                $password = $merchant->getPassword();

                $insertQuery = sprintf('INSERT INTO %s (`password`) VALUES (:password)', $this->table);
                $statement = $this->db->prepare($insertQuery);
                $statement->bindParam(':password', $password);
                $statement->execute();

                $result = $statement->fetch(\PDO::FETCH_ASSOC);
            }

            $merchant->setId($result['id'])
                ->setHost($result['host'])
                ->setPassword($result['password'])
                ->setOffer($result['offer'])
                ->setDestination($result['destination']);
        } catch (\PDOException $e) {
            $this->logger->addError($e);
        }

        return $merchant;
    }

    public function getMerchant()
    {
        return $this->merchant;
    }

    public function setMerchant(Merchant $merchant)
    {
        if (!Merchant::compare($this->merchant, $merchant)) {
            $this->save($merchant);
        }

        return $this;
    }

    private function save(Merchant $new)
    {
        if (empty($this->merchant)) {
            return;
        }

        try {
            $saveQuery = sprintf(
                'UPDATE %s SET `host`=:host, `password`=:password, `offer`=:offer, `destination`=:destination WHERE `id`=:id',
                $this->table
            );
            $statement = $this->db->prepare($saveQuery);
            $statement->bindParam('host', $new->getHost());
            $statement->bindParam('password', $new-><PASSWORD>());
            $statement->bindParam('offer', $new->getOffer());
            $statement->bindParam('destination', $new->getDestination());
            $statement->bindParam('id', $this->merchant->getId());
            $statement->execute();

            $this->merchant = $new;
        } catch (\PDOException $e) {
            $this->logger->addError($e);
        }
    }
}<commit_msg>Missing parameter on default MerchantProvider<commit_after><?php

namespace Expressly\Provider;

use Expressly\Entity\Merchant;
use Silex\Application;

class MerchantProvider implements MerchantProviderInterface
{
    private $db;
    private $logger;
    private $table;
    private $merchant;

    public function __construct(Application $app)
    {
        $this->db = $app['db'];
        $this->logger = $app['logger'];
        $this->table = $app['config']['table']['merchant'];
        $this->merchant = $this->firstOrCreate();
    }

    private function firstOrCreate()
    {
        $merchant = new Merchant();

        try {
            $getQuery = sprintf('SELECT * FROM %s LIMIT 1', $this->table);
            $statement = $this->db->prepare($getQuery);
            $statement->execute();

            $result = $statement->fetch(\PDO::FETCH_ASSOC);

            if (empty($result)) {
                $merchant->setPassword(Merchant::createPassword());
                $password = $merchant->getPassword();

                $insertQuery = sprintf('INSERT INTO %s (`password`) VALUES (:password)', $this->table);
                $statement = $this->db->prepare($insertQuery);
                $statement->bindParam(':password', $password);
                $statement->execute();

                $result = $statement->fetch(\PDO::FETCH_ASSOC);
            }

            $merchant->setId($result['id'])
                ->setHost($result['host'])
                ->setPassword($result['password'])
                ->setOffer($result['offer'])
                ->setDestination($result['destination']);
        } catch (\PDOException $e) {
            $this->logger->addError($e);
        }

        return $merchant;
    }

    public function getMerchant()
    {
        return $this->merchant;
    }

    public function setMerchant(Merchant $merchant)
    {
        if (!Merchant::compare($this->merchant, $merchant)) {
            $this->save($merchant);
        }

        return $this;
    }

    private function save(Merchant $new)
    {
        if (empty($this->merchant)) {
            return;
        }

        try {
            $saveQuery = sprintf(
                'UPDATE %s SET `host`=:host, `password`=:password, `offer`=:offer, `destination`=:destination WHERE `id`=:id',
                $this->table
            );
            $statement = $this->db->prepare($saveQuery);
            $statement->bindParam('host', $new->getHost());
            $statement->bindParam('password', $<PASSWORD>());
            $statement->bindParam('offer', $new->getOffer());
            $statement->bindParam('destination', $new->getDestination());
            $statement->bindParam('id', $this->merchant->getId());
            $statement->execute();

            $this->merchant = $new;
        } catch (\PDOException $e) {
            $this->logger->addError($e);
        }
    }
}
{'fraction_non_alphanumeric': 0.16442660150113458, 'fraction_numerical': 0.00034910106475824753, 'mean_word_length': 2.0740343347639487, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 98, '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': '2866847', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1552, 'n_words': 274}