Skip to content

Sweetchuck/robo-stringy

Repository files navigation

Robo Stringy

CircleCI codecov

This Robo task is useful when you need to do string manipulation in a \Robo\State\Data.

Install

composer require sweetchuck/robo-stringy

Task - taskStringy()

<?php

class RoboFile extends \Robo\Tasks
{
    use \Sweetchuck\Robo\Stringy\StringyTaskLoader;
    
    /**
     * @command stringy:simple
     */
    public function cmdStringySimple(string $text = 'Hello', string $suffix = 'World')
    {
        return $this
            ->collectionBuilder()
            ->addTask(
                $this
                    ->taskStringy()
                    ->setString($text)
                    ->callIsUpperCase()
                    ->callAppend(" $suffix")
                    ->callUnderscored()
            )
            ->addCode(function (\Robo\State\Data $data): int {
                $output = $this->output();
                $output->writeln('Is upper case: ' . var_export($data['stringy.isUpperCase'], true));
                $output->writeln("Result: {$data['stringy']}");

                return 0;
            });
    }
}

Run vendor/bin/robo stringy:simple
Output:

Is upper case: false
Result: hello_world

Run vendor/bin/robo stringy:simple FOO
Output:

Is upper case: true
Result: f_o_o_world