-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from dereuromark/3.x-backport
3.x backport more tasks from 4.x
- Loading branch information
Showing
61 changed files
with
2,404 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace IdeHelper\Generator\Directive; | ||
|
||
/** | ||
* Helps to annotate expected exit point methods. | ||
* | ||
* This is available since PhpStorm 2020.01 | ||
* | ||
* ### Example | ||
* | ||
* exitPoint(\Cake\Console\ConsoleIo::abort()); | ||
* | ||
* @see https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html#define-exit-points | ||
*/ | ||
class ExitPoint extends BaseDirective { | ||
|
||
const NAME = 'exitPoint'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $method; | ||
|
||
/** | ||
* @param string $method | ||
*/ | ||
public function __construct($method) { | ||
$this->method = $method; | ||
} | ||
|
||
/** | ||
* Key for sorting inside collection. | ||
* | ||
* @return string | ||
*/ | ||
public function key() { | ||
return $this->method . '@' . static::NAME; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() { | ||
return [ | ||
'method' => $this->method, | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function build() { | ||
$method = $this->method; | ||
|
||
$result = <<<TXT | ||
exitPoint($method); | ||
TXT; | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace IdeHelper\Generator\Task; | ||
|
||
use Cake\Cache\Cache; | ||
use IdeHelper\Generator\Directive\ExpectedArguments; | ||
use IdeHelper\Generator\Directive\RegisterArgumentsSet; | ||
use IdeHelper\ValueObject\StringName; | ||
|
||
class CacheTask implements TaskInterface { | ||
|
||
const CLASS_CACHE = Cache::class; | ||
|
||
const SET_CACHE_ENGINES = 'cacheEngines'; | ||
|
||
/** | ||
* @var int[] | ||
*/ | ||
protected $aliases = [ | ||
'\\' . self::CLASS_CACHE . '::clear()' => 0, | ||
'\\' . self::CLASS_CACHE . '::read()' => 1, | ||
'\\' . self::CLASS_CACHE . '::readMany()' => 1, | ||
'\\' . self::CLASS_CACHE . '::delete()' => 1, | ||
'\\' . self::CLASS_CACHE . '::deleteMany()' => 1, | ||
'\\' . self::CLASS_CACHE . '::clearGroup()' => 1, | ||
'\\' . self::CLASS_CACHE . '::add()' => 2, | ||
'\\' . self::CLASS_CACHE . '::write()' => 2, | ||
'\\' . self::CLASS_CACHE . '::increment()' => 2, | ||
'\\' . self::CLASS_CACHE . '::decrement()' => 2, | ||
'\\' . self::CLASS_CACHE . '::remember()' => 2, | ||
]; | ||
|
||
/** | ||
* @return \IdeHelper\Generator\Directive\BaseDirective[] | ||
*/ | ||
public function collect() { | ||
$result = []; | ||
|
||
$list = $this->collectCacheEngines(); | ||
$registerArgumentsSet = new RegisterArgumentsSet(static::SET_CACHE_ENGINES, $list); | ||
$result[$registerArgumentsSet->key()] = $registerArgumentsSet; | ||
|
||
foreach ($this->aliases as $alias => $position) { | ||
$directive = new ExpectedArguments($alias, $position, [$registerArgumentsSet]); | ||
$result[$directive->key()] = $directive; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return \IdeHelper\ValueObject\StringName[] | ||
*/ | ||
protected function collectCacheEngines() { | ||
$cacheEngines = Cache::configured(); | ||
|
||
$result = []; | ||
foreach ($cacheEngines as $cacheEngine) { | ||
$result[$cacheEngine] = StringName::create($cacheEngine); | ||
} | ||
|
||
ksort($result); | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace IdeHelper\Generator\Task; | ||
|
||
use Cake\Datasource\ConnectionManager; | ||
use IdeHelper\Generator\Directive\ExpectedArguments; | ||
use IdeHelper\ValueObject\StringName; | ||
|
||
class ConnectionTask extends ModelTask { | ||
|
||
const METHOD_GET = '\\' . ConnectionManager::class . '::get()'; | ||
|
||
/** | ||
* @return \IdeHelper\Generator\Directive\BaseDirective[] | ||
*/ | ||
public function collect() { | ||
$result = []; | ||
|
||
$keys = $this->connectionKeys(); | ||
|
||
ksort($keys); | ||
|
||
$directive = new ExpectedArguments(static::METHOD_GET, 0, $keys); | ||
$result[$directive->key()] = $directive; | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return \IdeHelper\ValueObject\StringName[] | ||
*/ | ||
protected function connectionKeys() { | ||
$configured = ConnectionManager::configured(); | ||
|
||
$list = []; | ||
foreach ($configured as $key) { | ||
$list[$key] = StringName::create($key); | ||
} | ||
|
||
return $list; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace IdeHelper\Generator\Task; | ||
|
||
use Cake\Console\ConsoleIo; | ||
use IdeHelper\Generator\Directive\ExitPoint; | ||
|
||
class ConsoleTask implements TaskInterface { | ||
|
||
const METHOD_ABORT = '\\' . ConsoleIo::class . '::abort()'; | ||
|
||
/** | ||
* @return \IdeHelper\Generator\Directive\BaseDirective[] | ||
*/ | ||
public function collect() { | ||
$result = []; | ||
|
||
$directive = new ExitPoint(static::METHOD_ABORT); | ||
$result[$directive->key()] = $directive; | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace IdeHelper\Generator\Task; | ||
|
||
use Cake\Datasource\ConnectionManager; | ||
use IdeHelper\Generator\Directive\ExpectedArguments; | ||
use IdeHelper\Generator\Directive\RegisterArgumentsSet; | ||
use IdeHelper\ValueObject\StringName; | ||
|
||
/** | ||
* This task is useful when using Migrations plugin and creating Migration files. | ||
*/ | ||
class DatabaseTableColumnNameTask extends DatabaseTableTask { | ||
|
||
const SET_TABLE_NAMES = 'tableNames'; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $aliases = [ | ||
'\Migrations\Table::addColumn()', | ||
'\Migrations\Table::changeColumn()', | ||
'\Migrations\Table::removeColumn()', | ||
'\Migrations\Table::renameColumn()', | ||
'\Migrations\Table::hasColumn()', | ||
]; | ||
|
||
/** | ||
* @return \IdeHelper\Generator\Directive\BaseDirective[] | ||
*/ | ||
public function collect() { | ||
$list = []; | ||
|
||
$names = $this->collectTableColumnNames(); | ||
foreach ($names as $type) { | ||
$list[$type] = StringName::create($type); | ||
} | ||
|
||
ksort($list); | ||
|
||
$result = []; | ||
$registerArgumentsSet = new RegisterArgumentsSet(static::SET_TABLE_NAMES, $list); | ||
$result[$registerArgumentsSet->key()] = $registerArgumentsSet; | ||
|
||
foreach ($this->aliases as $alias) { | ||
$directive = new ExpectedArguments($alias, 0, [$registerArgumentsSet]); | ||
$result[$directive->key()] = $directive; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
protected function collectTableColumnNames() { | ||
$schema = $this->getConnection()->getSchemaCollection(); | ||
|
||
$tables = $this->collectTables(); | ||
|
||
$columns = []; | ||
foreach ($tables as $table) { | ||
$tableSchema = $schema->describe($table); | ||
$columns = array_merge($columns, $tableSchema->columns()); | ||
} | ||
|
||
return array_unique($columns); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return \Cake\Database\Connection | ||
*/ | ||
protected function getConnection($name = 'default') { | ||
/** @var \Cake\Database\Connection $connection */ | ||
$connection = ConnectionManager::get($name); | ||
|
||
return $connection; | ||
} | ||
|
||
} |
Oops, something went wrong.