From 799de8d702f2d162ac5ef60c8103f8b6c6b79201 Mon Sep 17 00:00:00 2001 From: madflow Date: Tue, 28 Apr 2020 20:31:03 +0200 Subject: [PATCH] remove stringy --- composer.json | 7 ++-- src/Cheesecake/Generator.php | 44 ++++++++++++------------- tests/Cheesecake/Test/GeneratorTest.php | 4 +-- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index a33ca02..a0c0afb 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,10 @@ "mustache/mustache": "^2.9", "docopt/docopt": "1.0.0", "cypresslab/gitelephant": "~3.0", - "danielstjules/stringy": "~3.1.0", "wp-cli/php-cli-tools": "^0.10.5", - "symfony/process": "~3.0", - "symfony/filesystem": "~3.0", - "symfony/finder": "~3.0" + "symfony/process": "^3.4||^4.4||^5.0", + "symfony/filesystem": "^3.4||^4.4||^5.0", + "symfony/finder": "^3.4||^4.4||^5.0" }, "require-dev": { "phpunit/phpunit": "^7.4" diff --git a/src/Cheesecake/Generator.php b/src/Cheesecake/Generator.php index c9427d1..d97f02d 100644 --- a/src/Cheesecake/Generator.php +++ b/src/Cheesecake/Generator.php @@ -10,7 +10,6 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Finder\Finder; use GitElephant\Repository; -use Stringy\StaticStringy as Stringy; use cli; class Generator @@ -20,8 +19,8 @@ class Generator const TEMPLATE_TYPE_REMOTE_GIT = 2; const TEMPLATE_TYPE_LOCAL_GIT = 3; - const OPT_OUTPUT='OUTPUTDIR'; - const OPT_NO_INTERACTION='--no-interaction'; + const OPT_OUTPUT = 'OUTPUTDIR'; + const OPT_NO_INTERACTION = '--no-interaction'; private $template; private $templateType; @@ -55,28 +54,30 @@ public function __construct($template, array $params = [], array $options = []) $this->mustache = new \Mustache_Engine($options); $this->mustache->addHelper('string', [ 'toLowerCase' => function ($value) { - return Stringy::toLowerCase($value); + return \strtolower($value); }, 'toUpperCase' => function ($value) { - return Stringy::toUpperCase($value); + return \strtoupper($value); }, 'upperCaseFirst' => function ($value) { - return Stringy::upperCaseFirst($value); + return \ucfirst($value); }, 'lowerCaseFirst' => function ($value) { - return Stringy::lowerCaseFirst($value); + return \lcfirst($value); }, 'humanize' => function ($value) { - return Stringy::humanize($value); + $str = \str_replace(['_id', '_'], ['', ' '], $value); + return \ucfirst(\trim($str)); }, 'camelize' => function ($value) { - return Stringy::camelize($value); + return \lcfirst(\str_replace(' ', '', \ucwords(\preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $value)))); }, 'upperCamelize' => function ($value) { - return Stringy::upperCamelize($value); + return \ucfirst(\str_replace(' ', '', \ucwords(\preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $value)))); }, 'slugify' => function ($value) { - return Stringy::slugify($value); + $clean = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $value))); + return trim($clean, '-'); }, ]); $this->fs = new Filesystem(); @@ -84,9 +85,7 @@ public function __construct($template, array $params = [], array $options = []) private function getoa(array $options, $name, $default) { - return ( - isset($options[$name]) || isset($options['--'.$name]) - ) ? $options[$name] : $default; + return (isset($options[$name]) || isset($options['--' . $name])) ? $options[$name] : $default; } private function detectTemplateType($template) @@ -99,9 +98,11 @@ private function detectTemplateType($template) } } - if (Stringy::startsWith($template, 'https') - || Stringy::startsWith($template, 'git')) { - return self::TEMPLATE_TYPE_REMOTE_GIT; + if ( + substr($template, 0, 4) === "https" || + substr($template, 0, 4) === "git" + ) { + return self::TEMPLATE_TYPE_REMOTE_GIT; } return self::TEMPLATE_TYPE_UNKNOWN; @@ -119,9 +120,9 @@ public function run() $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json'); $localTemplate = $repo->getPath(); } elseif ($this->templateType === self::TEMPLATE_TYPE_LOCAL_GIT) { - $repo = Repository::open($this->template); - $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json'); - $localTemplate = $repo->getPath(); + $repo = Repository::open($this->template); + $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json'); + $localTemplate = $repo->getPath(); } else { throw new CheesecakeUnknownTemplateException(); } @@ -182,7 +183,7 @@ public function run() try { $this->fs->mirror($tmpDir, $this->output); - } catch(IOException $e) { + } catch (IOException $e) { throw new CheesecakeFilesystemExeption(); } @@ -202,7 +203,6 @@ public function run() } catch (IOException $e) { throw new CheesecakeFilesystemExeption(); } - } return true; diff --git a/tests/Cheesecake/Test/GeneratorTest.php b/tests/Cheesecake/Test/GeneratorTest.php index 1000da2..33f7b56 100644 --- a/tests/Cheesecake/Test/GeneratorTest.php +++ b/tests/Cheesecake/Test/GeneratorTest.php @@ -112,10 +112,10 @@ public function testFilters() $json->humanize, 'Hello Good Sir!' ); $this->assertEquals( - $json->camelize, 'helloGoodSir!' + $json->camelize, 'helloGoodSir' ); $this->assertEquals( - $json->upperCamelize, 'HelloGoodSir!' + $json->upperCamelize, 'HelloGoodSir' ); $this->assertEquals( $json->lowerCaseFirst, 'hello Good Sir!'