public function executeCommand(string $cmd, array $arguments = [], array $options = [])
    {
        $options = array_replace(
            [
                'overrideExitCode'  => null,
                'exceptionMessage'  => 'There was an error while executing the command.',
                'returnString'      => false,
                'implodeSeparator'  => PHP_EOL,
                'postCommand'       => ''
            ],
            $options
        );

        foreach ($arguments as $arg) {
            $cmd .= ' '.escapeshellarg($arg);
        }

        $cmd .= $options['postCommand'];

        exec($cmd, $output, $status);

        $status = $status && $options['overrideExitCode'] ?
            $options['overrideExitCode'] :
            $status;

        $this->_lastExecutedCommand['cmd'] = $cmd;
        $this->_lastExecutedCommand['arguments'] = $arguments;
        $this->_lastExecutedCommand['options'] = $options;
        $this->_lastExecutedCommand['output'] = $output;
        $this->_lastExecutedCommand['exitCode'] = $status;

        if ($status) {
            throw CommandException::create(
                $options['exceptionMessage'],
                $options['overrideExitCode'] ? $options['overrideExitCode'] : $status,
                $output,
                $cmd,
                $arguments
            );
        }

        return $options['returnString'] ?
            implode($options['implodeSeparator'], $output) :
            $output;
    }