<commit_before><?php

namespace Docker\Manager;

use Docker\Container;
use Docker\Http\Stream\InteractiveStream;
use Docker\Json;
use Docker\Exception\UnexpectedStatusCodeException;
use Docker\Exception\ContainerNotFoundException;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\RequestException;

/**
 * Docker\Manager\ContainerManager
 */
class ContainerManager
{
    /**
     * @var \GuzzleHttp\Client
     */
    private $client;

    /**
     * @param \GuzzleHttp\Client
     */
    public function __construct(HttpClient $client)
    {
        $this->client = $client;
    }

    /**
     * Get all containers from the docker daemon
     *
     * @param array $params an array of query parameters
     *
     * @throws \Docker\Exception\UnexpectedStatusCodeException
     *
     * @return Container[]
     */
    public function findAll(array $params = array())
    {
        $response = $this->client->get('/containers/json', [
            'query' => $params
        ]);

        if ($response->getStatusCode() !== "200") {
            throw UnexpectedStatusCodeException::fromResponse($response);
        }

        $coll = [];

        $containers = $response->json();

        if (!is_array($containers)) {
            return [];
        }

        foreach ($containers as $data) {
            $container = new Container();
            $container->setId($data['Id']);
            $container->setImage($data['Image']);
            $container->setCmd((array) $data['Command']);

            $container->setData($data);

            $coll[] = $container;
        }

        return $coll;
    }

    /**
     * Find a container by its id
     *
     * @param string $id
     *
     * @return \Docker\Container|null
     */
    public function find($id)
    {
        $container = new Container();
        $container->setId($id);

        try {
            $this->inspect($container);
        } catch (ContainerNotFoundException $e) {
            return null;
        }

        return $container;
    }

    /**
     * Inspect a container
     *
     * @param \Docker\Container $container
     *
     * @throws \GuzzleHttp\Exception\RequestException
     * @throws \Docker\Exception\ContainerNotFoundException
     *
     * @return ContainerManager
     */
    public function inspect(Container $container)
    {
        try {
            $response = $this->client->get(['/containers/{id}/json', ['id' => $container->getId()]]);
        } catch (RequestException $e) {
            if ($e->hasResponse() && $e->getResponse()->getStatusCode() == "404") {
                throw new ContainerNotFoundException($container->getId(), $e);
            }

            throw $e;
        }

        $container->setRuntimeInformations($response->json());

        return $this;
    }

    /**
     * Create a container (do not start it)
     *
     * @param \Docker\Container $container
     *
     * @throws \Docker\Exception\UnexpectedStatusCodeException
     *
     * @return \Docker\Manager\ContainerManager
     */<commit_msg>container inspect: send back json data<commit_after><?php

namespace Docker\Manager;

use Docker\Container;
use Docker\Http\Stream\InteractiveStream;
use Docker\Json;
use Docker\Exception\UnexpectedStatusCodeException;
use Docker\Exception\ContainerNotFoundException;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Exception\RequestException;

/**
 * Docker\Manager\ContainerManager
 */
class ContainerManager
{
    /**
     * @var \GuzzleHttp\Client
     */
    private $client;

    /**
     * @param \GuzzleHttp\Client
     */
    public function __construct(HttpClient $client)
    {
        $this->client = $client;
    }

    /**
     * Get all containers from the docker daemon
     *
     * @param array $params an array of query parameters
     *
     * @throws \Docker\Exception\UnexpectedStatusCodeException
     *
     * @return Container[]
     */
    public function findAll(array $params = array())
    {
        $response = $this->client->get('/containers/json', [
            'query' => $params
        ]);

        if ($response->getStatusCode() !== "200") {
            throw UnexpectedStatusCodeException::fromResponse($response);
        }

        $coll = [];

        $containers = $response->json();

        if (!is_array($containers)) {
            return [];
        }

        foreach ($containers as $data) {
            $container = new Container();
            $container->setId($data['Id']);
            $container->setImage($data['Image']);
            $container->setCmd((array) $data['Command']);

            $container->setData($data);

            $coll[] = $container;
        }

        return $coll;
    }

    /**
     * Find a container by its id
     *
     * @param string $id
     *
     * @return \Docker\Container|null
     */
    public function find($id)
    {
        $container = new Container();
        $container->setId($id);

        try {
            $this->inspect($container);
        } catch (ContainerNotFoundException $e) {
            return null;
        }

        return $container;
    }

    /**
     * Inspect a container
     *
     * @param \Docker\Container $container
     *
     * @throws \GuzzleHttp\Exception\RequestException
     * @throws \Docker\Exception\ContainerNotFoundException
     *
     * @return ContainerManager
     */
    public function inspect(Container $container)
    {
        try {
            $response = $this->client->get(['/containers/{id}/json', ['id' => $container->getId()]]);
        } catch (RequestException $e) {
            if ($e->hasResponse() && $e->getResponse()->getStatusCode() == "404") {
                throw new ContainerNotFoundException($container->getId(), $e);
            }

            throw $e;
        }

        $container->setRuntimeInformations($response->json());

        return $response->json();
    }

    /**
     * Create a container (do not start it)
     *
     * @param \Docker\Container $container
     *
     * @throws \Docker\Exception\UnexpectedStatusCodeException
     *
     * @return \Docker\Manager\ContainerManager
     */
{'fraction_non_alphanumeric': 0.13687653311529027, 'fraction_numerical': 0.0019623875715453804, 'mean_word_length': 2.0904497220818596, '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': '354309', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1648, 'n_words': 339}