Source of file ComposerAddKeywords.php
Size: 1,754 Bytes - Last Modified: 2021-12-23T10:42:13+00:00
/var/www/docs.ssmods.com/process/src/src/Commands/UpdateComposer/ComposerAddKeywords.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 | <?php namespace Sunnysideup\ModuleChecks\Commands\UpdateComposer; use Sunnysideup\ModuleChecks\Commands\UpdateComposerAbstract; class ComposerAddKeywords extends UpdateComposerAbstract { protected $defaultWords = [ 'Silverstripe', 'CMS', 'Silverstripe-CMS', ]; /** * should it be included by default? * @var bool */ private static $enabled = true; public function run(): bool { $this->removeKeyWords($this->defaultWords); $json = $this->composerJsonObj->getJsonData(); if (! is_array($json['keywords'])) { $json['keywords'] = []; } foreach ($this->defaultWords as $word) { array_unshift($json['keywords'], $word); } $json = $this->composerJsonObj->setJsonData($json); } /** * what does it do? * @return string */ public function getDescription(): string { return 'Add basic keywords (e.g. Silverstripe) to composer file'; } private function removeKeyWords($array) { $json = $this->composerJsonObj->getJsonData(); $clean = true; if (is_array($json['keywords'])) { foreach ($array as $word) { $index = array_search(strtolower($word), array_map('strtolower', $json['keywords']), true); if ($index !== false) { $clean = false; unset($json['keywords'][$index]); } } if (! $clean) { //update ... $this->composerJsonObj->setJsonData($json); //run again ... $this->removeKeyWords($array); } } return $clean; } } |