<commit_before><?php
declare(strict_types = 1);

namespace Enm\ShopwareSdk;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Enm\ShopwareSdk\Endpoint\ArticleEndpoint;
use Enm\ShopwareSdk\Endpoint\Definition\ArticleEndpointInterface;
use Enm\ShopwareSdk\Endpoint\Definition\OrderEndpointInterface;
use Enm\ShopwareSdk\Endpoint\OrderEndpoint;
use Enm\ShopwareSdk\Http\ClientInterface;
use Enm\ShopwareSdk\Http\GuzzleAdapter;
use Enm\ShopwareSdk\Model\Article\ArticleInterface;
use Enm\ShopwareSdk\Model\Order\OrderInterface;
use Enm\ShopwareSdk\Response\ArticleHandler;
use Enm\ShopwareSdk\Response\HandlerInterface;
use Enm\ShopwareSdk\Response\OrderHandler;
use GuzzleHttp\Client;
use JMS\Serializer\SerializerBuilder;

/**
 * @author <NAME> <<EMAIL>>
 */
class EntryPoint implements EntryPointInterface
{

    /**
     * @var ClientInterface
     */
    private $httpClient;

    /**
     * @var HandlerInterface[]
     */
    private $responseHandlers = [];

    /**
     * @var ArticleEndpointInterface
     */
    private $articleEndpoint;

    /**
     * @var OrderEndpointInterface
     */
    private $orderEndpoint;

    /**
     * @param ClientInterface $httpClient
     */
    public function __construct(ClientInterface $httpClient)
    {
        $this->httpClient = $httpClient;
    }

    /**
     * @param string $baseUri
     * @param string $username
     * @param string $password
     *
     * @return EntryPoint
     */
    public static function buildDefault(string $baseUri, string $username, string $password): EntryPoint
    {
        AnnotationRegistry::registerAutoloadNamespace(
            'JMS\Serializer\Annotation',
            __DIR__.'/../vendor/jms/serializer/src'
        );

        $serializer = SerializerBuilder::create()->build();

        $client = new GuzzleAdapter(new Client());
        $client->withConfig($baseUri, $username, $password);

        $entryPoint = new self($client);
        $entryPoint->addResponseHandler(new ArticleHandler($serializer));
        $entryPoint->addResponseHandler(new OrderHandler($serializer));

        return $entryPoint;
    }

    /**
     * @param HandlerInterface $handler
     *
     * @return EntryPoint
     */
    public function addResponseHandler(HandlerInterface $handler): EntryPoint
    {
        foreach ($handler->getSupportedTypes() as $type) {
            $this->responseHandlers[$type] = $handler;
        }

        return $this;
    }

    /**
     * @return ArticleEndpointInterface
     * @throws \InvalidArgumentException
     */
    public function articles(): ArticleEndpointInterface
    {
        if (!$this->articleEndpoint instanceof ArticleEndpointInterface) {
            $this->articleEndpoint = new ArticleEndpoint(
                $this->httpClient(),
                $this->handlerFor(ArticleInterface::class)
            );
        }

        return $this->articleEndpoint;
    }

    /**
     * @return ClientInterface
     */
    protected function httpClient(): ClientInterface
    {
        return $this->httpClient;
    }

    /**
     * @param string $type
     *
     * @return HandlerInterface
     * @throws \InvalidArgumentException
     */
    protected function handlerFor(string $type): HandlerInterface
    {
        if (!array_key_exists($type, $this->responseHandlers)) {
            throw new \InvalidArgumentException('No handler for '.$type);
        }

        return $this->responseHandlers[$type];
    }

    /**
     * @return OrderEndpointInterface
     * @throws \InvalidArgumentException
     */
    public function orders(): OrderEndpointInterface
    {
        if (!$this->orderEndpoint instanceof OrderEndpointInterface) {
            $this->orderEndpoint = new OrderEndpoint(
                $this->httpClient(),
                $this->handlerFor(OrderInterface::class)
            );
        }

        return $this->orderEndpoint;
    }
}
<commit_msg>moved default response handlers to new method<commit_after><?php
declare(strict_types = 1);

namespace Enm\ShopwareSdk;

use Doctrine\Common\Annotations\AnnotationRegistry;
use Enm\ShopwareSdk\Endpoint\ArticleEndpoint;
use Enm\ShopwareSdk\Endpoint\Definition\ArticleEndpointInterface;
use Enm\ShopwareSdk\Endpoint\Definition\OrderEndpointInterface;
use Enm\ShopwareSdk\Endpoint\OrderEndpoint;
use Enm\ShopwareSdk\Http\ClientInterface;
use Enm\ShopwareSdk\Http\GuzzleAdapter;
use Enm\ShopwareSdk\Model\Article\ArticleInterface;
use Enm\ShopwareSdk\Model\Order\OrderInterface;
use Enm\ShopwareSdk\Response\ArticleHandler;
use Enm\ShopwareSdk\Response\HandlerInterface;
use Enm\ShopwareSdk\Response\OrderHandler;
use GuzzleHttp\Client;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\SerializerInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
class EntryPoint implements EntryPointInterface
{
    
    /**
     * @var ClientInterface
     */
    private $httpClient;
    
    /**
     * @var HandlerInterface[]
     */
    private $responseHandlers = [];
    
    /**
     * @var ArticleEndpointInterface
     */
    private $articleEndpoint;
    
    /**
     * @var OrderEndpointInterface
     */
    private $orderEndpoint;
    
    /**
     * @param ClientInterface $httpClient
     */
    public function __construct(ClientInterface $httpClient)
    {
        $this->httpClient = $httpClient;
    }
    
    /**
     * @param string $baseUri
     * @param string $username
     * @param string $password
     *
     * @return EntryPoint
     */
    public static function buildDefault(string $baseUri, string $username, string $password): EntryPoint
    {
        AnnotationRegistry::registerAutoloadNamespace(
          'JMS\Serializer\Annotation',
          __DIR__.'/../vendor/jms/serializer/src'
        );
        
        $client = new GuzzleAdapter(new Client());
        $client->withConfig($baseUri, $username, $password);
        
        $entryPoint = new self($client);
        $entryPoint->addDefaultResponseHandlers(
          SerializerBuilder::create()->build()
        );
        
        return $entryPoint;
    }
    
    /**
     * @param SerializerInterface $serializer
     *
     * @return EntryPoint
     */
    public function addDefaultResponseHandlers(SerializerInterface $serializer): EntryPoint
    {
        $this->addResponseHandler(new ArticleHandler($serializer));
        $this->addResponseHandler(new OrderHandler($serializer));
        
        return $this;
    }
    
    /**
     * @param HandlerInterface $handler
     *
     * @return EntryPoint
     */
    public function addResponseHandler(HandlerInterface $handler): EntryPoint
    {
        foreach ($handler->getSupportedTypes() as $type) {
            $this->responseHandlers[$type] = $handler;
        }
        
        return $this;
    }
    
    /**
     * @return ArticleEndpointInterface
     * @throws \InvalidArgumentException
     */
    public function articles(): ArticleEndpointInterface
    {
        if (!$this->articleEndpoint instanceof ArticleEndpointInterface) {
            $this->articleEndpoint = new ArticleEndpoint(
              $this->httpClient(),
              $this->handlerFor(ArticleInterface::class)
            );
        }
        
        return $this->articleEndpoint;
    }
    
    /**
     * @return ClientInterface
     */
    protected function httpClient(): ClientInterface
    {
        return $this->httpClient;
    }
    
    /**
     * @param string $type
     *
     * @return HandlerInterface
     * @throws \InvalidArgumentException
     */
    protected function handlerFor(string $type): HandlerInterface
    {
        if (!array_key_exists($type, $this->responseHandlers)) {
            throw new \InvalidArgumentException('No handler for '.$type);
        }
        
        return $this->responseHandlers[$type];
    }
    
    /**
     * @return OrderEndpointInterface
     * @throws \InvalidArgumentException
     */
    public function orders(): OrderEndpointInterface
    {
        if (!$this->orderEndpoint instanceof OrderEndpointInterface) {
            $this->orderEndpoint = new OrderEndpoint(
              $this->httpClient(),
              $this->handlerFor(OrderInterface::class)
            );
        }
        
        return $this->orderEndpoint;
    }
}

{'fraction_non_alphanumeric': 0.10984342760043694, 'fraction_numerical': 0.00024274790629930817, 'mean_word_length': 2.56401384083045, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 50, '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': '5279366', 'n_tokens_mistral': 2242, 'n_tokens_neox': 2182, 'n_words': 408}