@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | /** |
| 41 | 41 | * @inheritdoc |
| 42 | 42 | */ |
| 43 | - public function options ( $actionID = null ) |
|
| 43 | + public function options($actionID = null) |
|
| 44 | 44 | { |
| 45 | 45 | return [ |
| 46 | 46 | 'component', |
@@ -51,52 +51,51 @@ discard block |
||
| 51 | 51 | /** |
| 52 | 52 | * @inheritdoc |
| 53 | 53 | */ |
| 54 | - public function optionAliases () |
|
| 54 | + public function optionAliases() |
|
| 55 | 55 | { |
| 56 | - return []; |
|
| 56 | + return [ ]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Shows description |
| 61 | 61 | */ |
| 62 | - public function showDescription () |
|
| 62 | + public function showDescription() |
|
| 63 | 63 | { |
| 64 | - $this->stdout( "Yii2 IDE auto-completion helper\n" ); |
|
| 65 | - $this->stdout( "Vitaliy IIIFX Khomenko, 2017\n\n" ); |
|
| 64 | + $this->stdout("Yii2 IDE auto-completion helper\n"); |
|
| 65 | + $this->stdout("Vitaliy IIIFX Khomenko, 2017\n\n"); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Generate IDE auto-completion file |
| 70 | 70 | */ |
| 71 | - public function actionIndex () |
|
| 71 | + public function actionIndex() |
|
| 72 | 72 | { |
| 73 | 73 | $this->showDescription(); |
| 74 | 74 | try { |
| 75 | 75 | $component = $this->getComponent(); |
| 76 | - $configList = $this->getConfig( $component ); |
|
| 77 | - $config = new Config( [ |
|
| 76 | + $configList = $this->getConfig($component); |
|
| 77 | + $config = new Config([ |
|
| 78 | 78 | 'files' => $configList, |
| 79 | - ] ); |
|
| 80 | - $builder = new Builder( [ |
|
| 79 | + ]); |
|
| 80 | + $builder = new Builder([ |
|
| 81 | 81 | 'components' => $config->getComponents(), |
| 82 | 82 | 'template' => require __DIR__ . '/template.php', |
| 83 | - ] ); |
|
| 84 | - if ( $component->result === null ) { |
|
| 85 | - $component->result = ( $this->getDetector()->detect() === 'basic' ) ? |
|
| 86 | - '@app/_ide_components.php' : |
|
| 87 | - '@console/../_ide_components.php'; |
|
| 83 | + ]); |
|
| 84 | + if ($component->result === null) { |
|
| 85 | + $component->result = ($this->getDetector()->detect() === 'basic') ? |
|
| 86 | + '@app/_ide_components.php' : '@console/../_ide_components.php'; |
|
| 88 | 87 | } |
| 89 | - $result = Yii::getAlias( $component->result ); |
|
| 90 | - $result = FileHelper::normalizePath( $result ); |
|
| 91 | - if ( $builder->build( $result ) ) { |
|
| 92 | - $this->stdout( "Success: {$result}\n", Console::FG_GREEN ); |
|
| 88 | + $result = Yii::getAlias($component->result); |
|
| 89 | + $result = FileHelper::normalizePath($result); |
|
| 90 | + if ($builder->build($result)) { |
|
| 91 | + $this->stdout("Success: {$result}\n", Console::FG_GREEN); |
|
| 93 | 92 | } else { |
| 94 | - $this->stdout( "Fail!\n", Console::FG_RED ); |
|
| 93 | + $this->stdout("Fail!\n", Console::FG_RED); |
|
| 95 | 94 | } |
| 96 | - } catch ( Exception $exception ) { |
|
| 97 | - $this->stdout( $exception->getMessage() . "\n\n", Console::FG_RED ); |
|
| 98 | - $this->stdout( "Please read the package documentation: https://github.com/iiifx-production/yii2-autocomplete-helper\n" ); |
|
| 99 | - $this->stdout( "or create new issue: https://github.com/iiifx-production/yii2-autocomplete-helper/issues/new\n" ); |
|
| 95 | + } catch (Exception $exception) { |
|
| 96 | + $this->stdout($exception->getMessage() . "\n\n", Console::FG_RED); |
|
| 97 | + $this->stdout("Please read the package documentation: https://github.com/iiifx-production/yii2-autocomplete-helper\n"); |
|
| 98 | + $this->stdout("or create new issue: https://github.com/iiifx-production/yii2-autocomplete-helper/issues/new\n"); |
|
| 100 | 99 | } |
| 101 | 100 | } |
| 102 | 101 | |
@@ -105,23 +104,23 @@ discard block |
||
| 105 | 104 | * |
| 106 | 105 | * @throws InvalidConfigException |
| 107 | 106 | */ |
| 108 | - protected function getComponent () |
|
| 107 | + protected function getComponent() |
|
| 109 | 108 | { |
| 110 | - if ( isset( Yii::$app->{$this->component} ) && Yii::$app->{$this->component} instanceof Component ) { |
|
| 109 | + if (isset(Yii::$app->{$this->component} ) && Yii::$app->{$this->component} instanceof Component) { |
|
| 111 | 110 | return Yii::$app->{$this->component}; |
| 112 | 111 | } |
| 113 | - throw new InvalidConfigException( sprintf( 'Component "%s" not found in Yii::$app', $this->component ) ); |
|
| 112 | + throw new InvalidConfigException(sprintf('Component "%s" not found in Yii::$app', $this->component)); |
|
| 114 | 113 | } |
| 115 | 114 | |
| 116 | 115 | /** |
| 117 | 116 | * @return Detector |
| 118 | 117 | */ |
| 119 | - protected function getDetector () |
|
| 118 | + protected function getDetector() |
|
| 120 | 119 | { |
| 121 | - if ( $this->detector === null ) { |
|
| 122 | - $this->detector = new Detector( [ |
|
| 120 | + if ($this->detector === null) { |
|
| 121 | + $this->detector = new Detector([ |
|
| 123 | 122 | 'app' => Yii::$app, |
| 124 | - ] ); |
|
| 123 | + ]); |
|
| 125 | 124 | } |
| 126 | 125 | return $this->detector; |
| 127 | 126 | } |
@@ -133,25 +132,25 @@ discard block |
||
| 133 | 132 | * |
| 134 | 133 | * @throws InvalidCallException |
| 135 | 134 | */ |
| 136 | - protected function getConfig ( Component $component ) |
|
| 135 | + protected function getConfig(Component $component) |
|
| 137 | 136 | { |
| 138 | - if ( $component->config === null ) { |
|
| 139 | - if ( $this->getDetector()->detect() === false ) { |
|
| 140 | - throw new InvalidCallException( 'Unable to determine application type' ); |
|
| 137 | + if ($component->config === null) { |
|
| 138 | + if ($this->getDetector()->detect() === false) { |
|
| 139 | + throw new InvalidCallException('Unable to determine application type'); |
|
| 141 | 140 | } |
| 142 | 141 | $configList = $this->getDetector()->getConfig(); |
| 143 | 142 | } else { |
| 144 | - if ( $this->config === null ) { |
|
| 145 | - if ( isset( $component->config[ 0 ] ) ) { |
|
| 143 | + if ($this->config === null) { |
|
| 144 | + if (isset($component->config[ 0 ])) { |
|
| 146 | 145 | $configList = $component->config; |
| 147 | 146 | } else { |
| 148 | - throw new InvalidCallException( 'Default config list not found in component config data' ); |
|
| 147 | + throw new InvalidCallException('Default config list not found in component config data'); |
|
| 149 | 148 | } |
| 150 | 149 | } else { |
| 151 | - if ( isset( $component->config[ $this->config ] ) ) { |
|
| 150 | + if (isset($component->config[ $this->config ])) { |
|
| 152 | 151 | $configList = $component->config[ $this->config ]; |
| 153 | 152 | } else { |
| 154 | - throw new InvalidCallException( sprintf( 'Scope "%s" not found in component config data', $this->config ) ); |
|
| 153 | + throw new InvalidCallException(sprintf('Scope "%s" not found in component config data', $this->config)); |
|
| 155 | 154 | } |
| 156 | 155 | } |
| 157 | 156 | } |
@@ -20,29 +20,29 @@ |
||
| 20 | 20 | /** |
| 21 | 21 | * @var array |
| 22 | 22 | */ |
| 23 | - public $components = []; |
|
| 23 | + public $components = [ ]; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @param string|false $file |
| 27 | 27 | * |
| 28 | 28 | * @return bool|string |
| 29 | 29 | */ |
| 30 | - public function build ( $file = null ) |
|
| 30 | + public function build($file = null) |
|
| 31 | 31 | { |
| 32 | - $prepared = preg_replace_callback( '/%.*%/U', function ( $m ) { |
|
| 33 | - if ( $m[ 0 ] === '%phpdoc%' ) { |
|
| 32 | + $prepared = preg_replace_callback('/%.*%/U', function($m) { |
|
| 33 | + if ($m[ 0 ] === '%phpdoc%') { |
|
| 34 | 34 | $string = '/**'; |
| 35 | - foreach ( $this->components as $name => $classes ) { |
|
| 36 | - $string .= PHP_EOL . ' * @property ' . implode( '|', $classes ) . ' $' . $name; |
|
| 35 | + foreach ($this->components as $name => $classes) { |
|
| 36 | + $string .= PHP_EOL . ' * @property ' . implode('|', $classes) . ' $' . $name; |
|
| 37 | 37 | } |
| 38 | 38 | $string .= PHP_EOL . ' */'; |
| 39 | 39 | return $string; |
| 40 | 40 | } |
| 41 | 41 | return $m[ 0 ]; |
| 42 | - }, $this->template ); |
|
| 43 | - if ( $file === null ) { |
|
| 42 | + }, $this->template); |
|
| 43 | + if ($file === null) { |
|
| 44 | 44 | return $prepared; |
| 45 | 45 | } |
| 46 | - return (bool) file_put_contents( $file, $prepared ); |
|
| 46 | + return (bool) file_put_contents($file, $prepared); |
|
| 47 | 47 | } |
| 48 | 48 | } |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * @return string|false |
| 52 | 52 | */ |
| 53 | - public function detect () |
|
| 53 | + public function detect() |
|
| 54 | 54 | { |
| 55 | 55 | $application = $this->getApplication(); |
| 56 | - if ( isset( $this->ids[ $application->id ] ) ) { |
|
| 56 | + if (isset($this->ids[ $application->id ])) { |
|
| 57 | 57 | return $this->ids[ $application->id ]; |
| 58 | 58 | } |
| 59 | 59 | return false; |
@@ -62,20 +62,20 @@ discard block |
||
| 62 | 62 | /** |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function getConfig () |
|
| 65 | + public function getConfig() |
|
| 66 | 66 | { |
| 67 | - if ( $type = $this->detect() ) { |
|
| 68 | - return isset( $this->configs[ $type ] ) ? $this->configs[ $type ] : []; |
|
| 67 | + if ($type = $this->detect()) { |
|
| 68 | + return isset($this->configs[ $type ]) ? $this->configs[ $type ] : [ ]; |
|
| 69 | 69 | } |
| 70 | - return []; |
|
| 70 | + return [ ]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * @return Application |
| 75 | 75 | */ |
| 76 | - protected function getApplication () |
|
| 76 | + protected function getApplication() |
|
| 77 | 77 | { |
| 78 | - if ( ! $this->app instanceof Application ) { |
|
| 78 | + if ( ! $this->app instanceof Application) { |
|
| 79 | 79 | $this->app = Yii::$app; |
| 80 | 80 | } |
| 81 | 81 | return $this->app; |
@@ -39,29 +39,29 @@ |
||
| 39 | 39 | /** |
| 40 | 40 | * @inheritdoc |
| 41 | 41 | */ |
| 42 | - public function bootstrap ( $app ) |
|
| 42 | + public function bootstrap($app) |
|
| 43 | 43 | { |
| 44 | - if ( $app instanceof \yii\console\Application && $this->isActive() ) { |
|
| 45 | - $this->updateControllerMap( $app ); |
|
| 44 | + if ($app instanceof \yii\console\Application && $this->isActive()) { |
|
| 45 | + $this->updateControllerMap($app); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @return bool |
| 51 | 51 | */ |
| 52 | - public function isActive () |
|
| 52 | + public function isActive() |
|
| 53 | 53 | { |
| 54 | - return defined( 'YII_ENV' ) && YII_ENV === $this->environment; |
|
| 54 | + return defined('YII_ENV') && YII_ENV === $this->environment; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * @param Application $app |
| 59 | 59 | */ |
| 60 | - protected function updateControllerMap ( Application $app ) |
|
| 60 | + protected function updateControllerMap(Application $app) |
|
| 61 | 61 | { |
| 62 | - if ( is_array( $this->controllerMap ) ) { |
|
| 63 | - foreach ( $this->controllerMap as $name => $controller ) { |
|
| 64 | - if ( is_subclass_of( $controller, \yii\console\Controller::class ) ) { |
|
| 62 | + if (is_array($this->controllerMap)) { |
|
| 63 | + foreach ($this->controllerMap as $name => $controller) { |
|
| 64 | + if (is_subclass_of($controller, \yii\console\Controller::class)) { |
|
| 65 | 65 | $app->controllerMap[ $name ] = $controller; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @var mixed[] |
| 21 | 21 | */ |
| 22 | - public $files = []; |
|
| 22 | + public $files = [ ]; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * @var mixed[] |
@@ -36,18 +36,18 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @throws \yii\base\InvalidParamException |
| 38 | 38 | */ |
| 39 | - public function getComponents () |
|
| 39 | + public function getComponents() |
|
| 40 | 40 | { |
| 41 | - if ( $this->_components === null ) { |
|
| 42 | - $this->_components = []; |
|
| 43 | - if ( $config = $this->readConfig() ) { |
|
| 44 | - foreach ( $this->files as $current ) { |
|
| 45 | - if ( isset( $config[ $current ][ 'components' ] ) ) { |
|
| 41 | + if ($this->_components === null) { |
|
| 42 | + $this->_components = [ ]; |
|
| 43 | + if ($config = $this->readConfig()) { |
|
| 44 | + foreach ($this->files as $current) { |
|
| 45 | + if (isset($config[ $current ][ 'components' ])) { |
|
| 46 | 46 | /** @var mixed[] $components */ |
| 47 | 47 | $components = $config[ $current ][ 'components' ]; |
| 48 | - if ( is_array( $components ) ) { |
|
| 49 | - foreach ( $components as $name => $component ) { |
|
| 50 | - if ( ( $class = $this->findClass( $component ) ) !== false ) { |
|
| 48 | + if (is_array($components)) { |
|
| 49 | + foreach ($components as $name => $component) { |
|
| 50 | + if (($class = $this->findClass($component)) !== false) { |
|
| 51 | 51 | $this->_components[ $name ][ $class ] = $class; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @throws \yii\base\InvalidParamException |
| 66 | 66 | */ |
| 67 | - protected function readConfig () |
|
| 67 | + protected function readConfig() |
|
| 68 | 68 | { |
| 69 | - if ( $this->_config === null ) { |
|
| 70 | - $this->_config = []; |
|
| 71 | - foreach ( $this->files as $file ) { |
|
| 72 | - $path = Yii::getAlias( $file ); |
|
| 73 | - $path = FileHelper::normalizePath( $path ); |
|
| 74 | - if ( is_file( $path ) ) { |
|
| 69 | + if ($this->_config === null) { |
|
| 70 | + $this->_config = [ ]; |
|
| 71 | + foreach ($this->files as $file) { |
|
| 72 | + $path = Yii::getAlias($file); |
|
| 73 | + $path = FileHelper::normalizePath($path); |
|
| 74 | + if (is_file($path)) { |
|
| 75 | 75 | try { |
| 76 | 76 | /** @noinspection PhpIncludeInspection */ |
| 77 | 77 | $this->_config[ $file ] = require $path; |
| 78 | - } catch ( Exception $exception ) { |
|
| 78 | + } catch (Exception $exception) { |
|
| 79 | 79 | # Ignore |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -89,22 +89,22 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return string|false |
| 91 | 91 | */ |
| 92 | - protected function findClass ( $section ) |
|
| 92 | + protected function findClass($section) |
|
| 93 | 93 | { |
| 94 | 94 | try { |
| 95 | - if ( $section instanceof Closure ) { |
|
| 96 | - return get_class( $section() ); |
|
| 95 | + if ($section instanceof Closure) { |
|
| 96 | + return get_class($section()); |
|
| 97 | 97 | } |
| 98 | - if ( is_object( $section ) ) { |
|
| 99 | - return get_class( $section ); |
|
| 98 | + if (is_object($section)) { |
|
| 99 | + return get_class($section); |
|
| 100 | 100 | } |
| 101 | - if ( is_string( $section ) ) { |
|
| 101 | + if (is_string($section)) { |
|
| 102 | 102 | return $section; |
| 103 | 103 | } |
| 104 | - if ( is_array( $section ) && isset( $section[ 'class' ] ) ) { |
|
| 104 | + if (is_array($section) && isset($section[ 'class' ])) { |
|
| 105 | 105 | return $section[ 'class' ]; |
| 106 | 106 | } |
| 107 | - } catch ( Exception $exception ) { |
|
| 107 | + } catch (Exception $exception) { |
|
| 108 | 108 | # Ignore |
| 109 | 109 | } |
| 110 | 110 | return false; |