<commit_before><?php

namespace Rezzza\JobFlow;

use Rezzza\JobFlow\Scheduler\ExecutionContext;

/**
 * @author <NAME> <<EMAIL>>
 */
class Job implements \IteratorAggregate, JobInterface
{
    /**
     * @var JobConfig
     */
    private $config;

    /**
     * @var JobInterface
     */
    private $parent;

    /**
     * @var JobInterface[]
     */
    protected $children = array();

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

    /**
     * {@inheritdoc}
     */
    public function setParent(JobInterface $parent = null)
    {
        if (null !== $parent && '' === $this->config->getName()) {
            throw new \LogicException('A job with an empty name cannot have a parent job.');
        }

        $this->parent = $parent;

        return $this;
    }

    /**
     * @var ExecutionContext $context
     */
    public function execute(ExecutionContext $context)
    {
        $input = $this->getInput($context);
        $output = $this->getOutput($context);

        $this->getResolved()->execute($input, $output, $context);

        return $output;
    }

    /**
     * @param JobInterface $child
     */
    public function add(JobInterface $child)
    {
        if ($this->isLocked()) {
            throw new \RuntimeException('Cannot add child on job locked');
        }

        $child->setParent($this);

        $this->children[$child->getName()] = $child;
    }

    /**
     * @param $name
     *
     * @return JobInterface
     */
    public function get($name)
    {
        if (!array_key_exists($name, $this->children)) {
            throw new \LogicException(sprintf('No child with name : "%s" in job "%s"', $name, $this->getName()));
        }

        return $this->children[$name];
    }

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

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

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

    /**
     * @return JobInterface[]
     */
    public function getChildren()
    {
        return $this->children;
    }

    /**
     * @param boolean $locked
     */
    public function setLocked($locked)
    {
        $this->locked = $locked;
    }

    /**
     * @return boolean
     */
    public function isLocked()
    {
        return false;
    }

    /**
     * @return JobInput
     */
    public function getInput(ExecutionContext $context)
    {
        $input = new JobInput();
        $source = null;

        if ($context->msg->hasData()) {
            $source = $context->msg->getData();
        } elseif ($context->isFirstStep()) {
            $etl = $this->getEtlConfig();
            $source = $etl['extractor'];
        }

        if (null === $source) {
            throw new \LogicException(sprintf('No data found for job "%s" input', $this->getFullName()));
        }

        $input->setSource($source);

        return $input;
    }

    /**
     * @return JobOutput
     */
    public function getOutput(ExecutionContext $context)
    {
        $output = new JobOutput();
        $destination = null;

        if ($context->isLastStep()) {
            $etl = $this->getEtlConfig();
            $destination = $etl['loader'];
        }

        $output->setDestination($destination);

        return $output;
    }

    /**
     * @return JobInterface
     */
    public function getParent()<commit_msg>Ensure we have etl config<commit_after><?php

namespace Rezzza\JobFlow;

use Rezzza\JobFlow\Scheduler\ExecutionContext;

/**
 * @author <NAME> <<EMAIL>>
 */
class Job implements \IteratorAggregate, JobInterface
{
    /**
     * @var JobConfig
     */
    private $config;

    /**
     * @var JobInterface
     */
    private $parent;

    /**
     * @var JobInterface[]
     */
    protected $children = array();

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

    /**
     * {@inheritdoc}
     */
    public function setParent(JobInterface $parent = null)
    {
        if (null !== $parent && '' === $this->config->getName()) {
            throw new \LogicException('A job with an empty name cannot have a parent job.');
        }

        $this->parent = $parent;

        return $this;
    }

    /**
     * @var ExecutionContext $context
     */
    public function execute(ExecutionContext $context)
    {
        $input = $this->getInput($context);
        $output = $this->getOutput($context);

        $this->getResolved()->execute($input, $output, $context);

        return $output;
    }

    /**
     * @param JobInterface $child
     */
    public function add(JobInterface $child)
    {
        if ($this->isLocked()) {
            throw new \RuntimeException('Cannot add child on job locked');
        }

        $child->setParent($this);

        $this->children[$child->getName()] = $child;
    }

    /**
     * @param $name
     *
     * @return JobInterface
     */
    public function get($name)
    {
        if (!array_key_exists($name, $this->children)) {
            throw new \LogicException(sprintf('No child with name : "%s" in job "%s"', $name, $this->getName()));
        }

        return $this->children[$name];
    }

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

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

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

    /**
     * @return JobInterface[]
     */
    public function getChildren()
    {
        return $this->children;
    }

    /**
     * @param boolean $locked
     */
    public function setLocked($locked)
    {
        $this->locked = $locked;
    }

    /**
     * @return boolean
     */
    public function isLocked()
    {
        return false;
    }

    /**
     * @return JobInput
     */
    public function getInput(ExecutionContext $context)
    {
        $input = new JobInput();
        $source = null;

        if ($context->msg->hasData()) {
            $source = $context->msg->getData();
        } elseif ($context->isFirstStep()) {
            $etl = $this->getEtlConfig();
            $source = isset($etl['extractor']) ? $etl['extractor'] : null;
        }

        if (null === $source) {
            throw new \LogicException(sprintf('No data found for job "%s" input', $this->getFullName()));
        }

        $input->setSource($source);

        return $input;
    }

    /**
     * @return JobOutput
     */
    public function getOutput(ExecutionContext $context)
    {
        $output = new JobOutput();
        $destination = null;

        if ($context->isLastStep()) {
            $etl = $this->getEtlConfig();
            $destination = isset($etl['loader']) ? $etl['loader'] : null;
        }

        $output->setDestination($destination);

        return $output;
    }

    /**
     * @return JobInterface
     */
    public function getParent()
{'fraction_non_alphanumeric': 0.15242494226327943, 'fraction_numerical': 0.0, 'mean_word_length': 1.8501742160278745, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 77, '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': '3278368', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2126, 'n_words': 463}