<commit_before><?php

namespace Docker;

use Docker\Exception\PortNotFoundException;

/**
 * Docker\Container
 */
class Container
{
    const STATUS_NEW = 0;

    const STATUS_CREATED = 1;

    const STATUS_STARTED = 2;

    /**
     * @var string
     */
    private $id;

    /**
     * @var array
     */
    private $config = array();

    /**
     * @var array
     */
    private $runtimeInformations = array();

    /**
     * @var null|integer
     */
    private $exitCode = null;

    /**
     * @var Docker\Image
     */
    private $image;

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

    /**
     * @return boolean
     */
    public function exists()
    {
        return strlen($this->id) > 0;
    }

    /**
     * @return array
     */
    public function getRuntimeInformations()
    {
        return $this->runtimeInformations;
    }

    /**
     * @param array $runtimeInformations
     *
     * @return Docker\Container
     */
    public function setRuntimeInformations($runtimeInformations)
    {
        $this->runtimeInformations = $runtimeInformations;

        return $this;
    }

    /**
     * @return array
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * @param integer $port
     * @param string  $protocol
     *
     * @return Docker\Port
     */
    public function getMappedPort($port, $protocol = 'tcp')
    {
        // Problem with $protohuik as a variable name? Harass @futurecat.
        $protohuik = $port.'/'.$protocol;

        if (!array_key_exists($protohuik, $this->runtimeInformations['NetworkSettings']['Ports'])) {
            throw new PortNotFoundException($port, $protocol);
        }

        $portInfo = $this->runtimeInformations['NetworkSettings']['Ports'][$protohuik];

        return new Port(sprintf('%s:%s:%s/%s', $portInfo[0]['HostIp'], $portInfo[0]['HostPort'], $port, $protocol));
    }

    /**
     * Accepts both (eg) 80 or 80/tcp as inputs.
     *
     * @param integer|string ...$ports
     *
     * @return array
     */
    public function getMappedPorts()
    {
        $ports = func_get_args();
        $mappedPorts = [];

        foreach ($ports as $protohuik) {
            // @todo better validation of $protohuik
            //       could use an instance of Port for example
            $parts = explode('/', $protohuik);

            if (count($parts) === 1) {
                $parts[] = 'tcp';
            }

            list($port, $protocol) = $parts;

            try {
                $mappedPort = $this->getMappedPort($port, $protocol);
            } catch (PortNotFoundException $e) {
                continue;
            }

            $mappedPorts[] = $mappedPort;
        }

        return $mappedPorts;
    }

    /**
     * @param string $id
     *
     * @return Docker\Container
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    /**
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return array_key_exists('Name', $this->runtimeInformations) ? $this->runtimeInformations['Name'] : null;
    }

    /**
     * @param integer $exitCode
     *
     * @return Docker\Container
     */
    public function setExitCode($exitCode)
    {
        $this->exitCode = (integer) $exitCode;

        return $this;
    }

    /**
     * @return integer
     */
    public function getExitCode()
    {
        return $this->exitCode;
    }

    /**
     * @param array|PortSpecInterface $ports
     *
     * @return Docker\Container
     */
    public function setExposedPorts($ports)
    {
        if ($ports instanceof PortSpecInterface) {
            $this->config['ExposedPorts'] = $ports->toExposedPorts();<commit_msg>try harder to find an exit code<commit_after><?php

namespace Docker;

use Docker\Exception\PortNotFoundException;

use LogicException;

/**
 * Docker\Container
 */
class Container
{
    const STATUS_NEW = 0;

    const STATUS_CREATED = 1;

    const STATUS_STARTED = 2;

    /**
     * @var string
     */
    private $id;

    /**
     * @var array
     */
    private $config = array();

    /**
     * @var array
     */
    private $runtimeInformations = array();

    /**
     * @var null|integer
     */
    private $exitCode = null;

    /**
     * @var Docker\Image
     */
    private $image;

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

    /**
     * @return boolean
     */
    public function exists()
    {
        return strlen($this->id) > 0;
    }

    /**
     * @return array
     */
    public function getRuntimeInformations()
    {
        return $this->runtimeInformations;
    }

    /**
     * @param array $runtimeInformations
     *
     * @return Docker\Container
     */
    public function setRuntimeInformations($runtimeInformations)
    {
        $this->runtimeInformations = $runtimeInformations;

        return $this;
    }

    /**
     * @return array
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * @param integer $port
     * @param string  $protocol
     *
     * @return Docker\Port
     */
    public function getMappedPort($port, $protocol = 'tcp')
    {
        // Problem with $protohuik as a variable name? Harass @futurecat.
        $protohuik = $port.'/'.$protocol;

        if (!array_key_exists($protohuik, $this->runtimeInformations['NetworkSettings']['Ports'])) {
            throw new PortNotFoundException($port, $protocol);
        }

        $portInfo = $this->runtimeInformations['NetworkSettings']['Ports'][$protohuik];

        return new Port(sprintf('%s:%s:%s/%s', $portInfo[0]['HostIp'], $portInfo[0]['HostPort'], $port, $protocol));
    }

    /**
     * Accepts both (eg) 80 or 80/tcp as inputs.
     *
     * @param integer|string ...$ports
     *
     * @return array
     */
    public function getMappedPorts()
    {
        $ports = func_get_args();
        $mappedPorts = [];

        foreach ($ports as $protohuik) {
            // @todo better validation of $protohuik
            //       could use an instance of Port for example
            $parts = explode('/', $protohuik);

            if (count($parts) === 1) {
                $parts[] = 'tcp';
            }

            list($port, $protocol) = $parts;

            try {
                $mappedPort = $this->getMappedPort($port, $protocol);
            } catch (PortNotFoundException $e) {
                continue;
            }

            $mappedPorts[] = $mappedPort;
        }

        return $mappedPorts;
    }

    /**
     * @param string $id
     *
     * @return Docker\Container
     */
    public function setId($id)
    {
        $this->id = $id;

        return $this;
    }

    /**
     * @return string
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return array_key_exists('Name', $this->runtimeInformations) ? $this->runtimeInformations['Name'] : null;
    }

    /**
     * @param integer $exitCode
     *
     * @return Docker\Container
     */
    public function setExitCode($exitCode)
    {
        $this->exitCode = (integer) $exitCode;

        return $this;
    }

    /**
     * @return integer
     */
    public function getExitCode()
    {
        if (null !== $this->exitCode) {
            return $this->exitCode;
        }

        if (is_array($this->runtimeInformations)) {
            return $this->runtimeInformations['State']['ExitCode'];
        }

        throw new LogicException('Could not find an exit code');
    }

    /**
     * @param array|PortSpecInterface $ports
     *
     * @return Docker\Container
     */
    public function setExposedPorts($ports)
    {
        if ($ports instanceof PortSpecInterface) {
            $this->config['ExposedPorts'] = $ports->toExposedPorts();
{'fraction_non_alphanumeric': 0.1379436964504284, 'fraction_numerical': 0.0026927784577723377, 'mean_word_length': 1.805012015104703, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '5653877', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2379, 'n_words': 514}