Skip to content

Commit

Permalink
updated tool for annotation updating
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Cheprasov committed Jan 12, 2016
1 parent 3d6f4c9 commit bf74189
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
vendor/
test.php
composer.lock
tools/back/
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@
beStrictAboutOutputDuringTests = "true"
beStrictAboutTestSize = "true"
>
<testsuites>
<testsuite name="All tests">
<directory suffix="Test.php" >./tests/</directory>
</testsuite>
</testsuites>

</phpunit>
8 changes: 4 additions & 4 deletions src/RedisClient/Client/Version/RedisClient2x6.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
namespace RedisClient\Client\Version;

use RedisClient\Client\AbstractRedisClient;
use RedisClient\Command\Traits\Version3x2\CommandsTrait;
use RedisClient\Command\Traits\Version2x6\CommandsTrait;
use RedisClient\Pipeline\PipelineInterface;
use RedisClient\Pipeline\Version\Pipeline3x2;
use RedisClient\Pipeline\Version\Pipeline2x6;

/**
* Class RedisClient
* @package RedisClient
*/
class RedisClient3x2 extends AbstractRedisClient {
class RedisClient2x6 extends AbstractRedisClient {
use CommandsTrait;

/**
* @param \Closure|null $Pipeline
* @return PipelineInterface
*/
protected function createPipeline(\Closure $Pipeline = null) {
return new Pipeline3x2($Pipeline);
return new Pipeline2x6($Pipeline);
}

}
8 changes: 4 additions & 4 deletions src/RedisClient/Client/Version/RedisClient2x8.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
namespace RedisClient\Client\Version;

use RedisClient\Client\AbstractRedisClient;
use RedisClient\Command\Traits\Version3x2\CommandsTrait;
use RedisClient\Command\Traits\Version2x8\CommandsTrait;
use RedisClient\Pipeline\PipelineInterface;
use RedisClient\Pipeline\Version\Pipeline3x2;
use RedisClient\Pipeline\Version\Pipeline2x8;

/**
* Class RedisClient
* @package RedisClient
*/
class RedisClient3x2 extends AbstractRedisClient {
class RedisClient2x8 extends AbstractRedisClient {
use CommandsTrait;

/**
* @param \Closure|null $Pipeline
* @return PipelineInterface
*/
protected function createPipeline(\Closure $Pipeline = null) {
return new Pipeline3x2($Pipeline);
return new Pipeline2x8($Pipeline);
}

}
8 changes: 4 additions & 4 deletions src/RedisClient/Client/Version/RedisClient2x9.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
namespace RedisClient\Client\Version;

use RedisClient\Client\AbstractRedisClient;
use RedisClient\Command\Traits\Version3x2\CommandsTrait;
use RedisClient\Command\Traits\Version2x9\CommandsTrait;
use RedisClient\Pipeline\PipelineInterface;
use RedisClient\Pipeline\Version\Pipeline3x2;
use RedisClient\Pipeline\Version\Pipeline2x9;

/**
* Class RedisClient
* @package RedisClient
*/
class RedisClient3x2 extends AbstractRedisClient {
class RedisClient2x9 extends AbstractRedisClient {
use CommandsTrait;

/**
* @param \Closure|null $Pipeline
* @return PipelineInterface
*/
protected function createPipeline(\Closure $Pipeline = null) {
return new Pipeline3x2($Pipeline);
return new Pipeline2x9($Pipeline);
}

}
2 changes: 1 addition & 1 deletion src/RedisClient/Pipeline/Version/Pipeline2x6.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
* @method $this multi()
* @method $this unwatch()
* @method $this watch($keys)
*
*
*/
class Pipeline2x6 extends AbstractPipeline {
use CommandsTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient/Pipeline/Version/Pipeline2x8.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
*
* Strings
* @method $this bitpos($key, $bit, $start = null, $end = null)
*
*
*/
class Pipeline2x8 extends AbstractPipeline {
use CommandsTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient/Pipeline/Version/Pipeline2x9.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
*
* Server
* @method $this clientPause($timeout)
*
*
*/
class Pipeline2x9 extends AbstractPipeline {
use CommandsTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient/Pipeline/Version/Pipeline3x0.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
*
* SortedSets
* @method $this zadd($key, array $members, $nx = null, $ch = false, $incr = false)
*
*
*/
class Pipeline3x0 extends AbstractPipeline {
use CommandsTrait;
Expand Down
2 changes: 1 addition & 1 deletion src/RedisClient/Pipeline/Version/Pipeline3x2.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
*
* Sets
* @method $this spop($key, $count = null)
*
*
*/
class Pipeline3x2 extends AbstractPipeline {
use CommandsTrait;
Expand Down
71 changes: 54 additions & 17 deletions tools/generate-annotations-for-pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
* file that was distributed with this source code.
*/

const EOL = "\n";

if ($argc === 2 && $argv[1] === '--help') {
echo '---'. PHP_EOL,
'Tools for generations annotations for Pipelines by versions'. PHP_EOL,
'Using: php ./tools/'. basename(__FILE__) .' > /save/to/file/path'. PHP_EOL,
'---'. PHP_EOL;
echo '---'. EOL,
'Tools for generations annotations for Pipelines by versions'. EOL,
'Using: php ./tools/'. basename(__FILE__) .' [update [backup]]'. EOL,
'---'. EOL;
exit;
}

$lines = `grep -r 'function' ./src/RedisClient/Command/Traits/`;

//Version3x0/SortedSetsCommandsTrait.php: public function zrange($key, $start, $stop, $withscores = false)
if (!preg_match_all('/Version(\d+x\d+)\/(\w+)CommandsTrait\.php.+public function (.+)\((.*)\)/im', $lines, $matches, PREG_SET_ORDER)) {
echo 'Not found'. PHP_EOL;
echo 'Not found'. EOL;
}

$versions = [];
Expand All @@ -42,20 +44,55 @@

ksort($versions);

$annotations = [];
foreach ($versions as $version => $groups) {
$annotations[] = '';
$annotations[] = 'Redis version '. str_replace('x', '.', $version);
foreach ($groups as $group => $commands) {
if (in_array('update', $argv)) {

$text = '';
foreach ($versions as $version => $groups) {
$annotations = [''];
$annotations[] = 'Redis version ' . ($ver = str_replace('x', '.', $version));
foreach ($groups as $group => $commands) {
$annotations[] = '';
$annotations[] = $group;
foreach ($commands as $command => $params) {
$annotations[] = '@method $this ' . $command . '(' . $params . ')';
// deactivation old version of commands
$text = str_replace('@method $this ' . $command . '(', '-method $this ' . $command . '(', $text);
}
}
$annotations[] = '';
$annotations[] = $group;
//$annotations[] = '';
foreach ($commands as $command => $params) {
$annotations[] = '@method $this '. $command .'('. $params .')';
$text .= implode("\n * ", $annotations);
$text = str_replace("\n * \n", "\n *\n", $text);

if (!file_exists($file = './src/RedisClient/Pipeline/Version/Pipeline'.$version.'.php')) {
continue;
}

$old = file_get_contents($file);
$new = preg_replace('/(?<=\/\*\*)\n (.+\n)+(?= \*\/\nclass Pipeline'.$version.')/', ($text).EOL, $old);
if ($new) {
echo 'File '. $file .' - updated'. EOL;
if (in_array('backup', $argv)) {
copy($file, $back = __DIR__ . '/back/Pipeline' . $version . '.php.' . date('Ymd.His'));
}
file_put_contents($file, $new);
}
}

}
$annotations[] = '';
} else {

$annotations = [];
foreach ($versions as $version => $groups) {
$annotations[] = '';
$annotations[] = 'Redis version ' . str_replace('x', '.', $version);
foreach ($groups as $group => $commands) {
$annotations[] = '';
$annotations[] = $group;
foreach ($commands as $command => $params) {
$annotations[] = '@method $this ' . $command . '(' . $params . ')';
}
}

echo "/**". implode("\n * ", $annotations) ."\n */";
}
$annotations[] = '';
echo "/**" . implode("\n * ", $annotations) . "\n */";
}

0 comments on commit bf74189

Please sign in to comment.