Skip to content

Commit

Permalink
php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
hparadiz committed May 21, 2018
1 parent f089c81 commit 1261887
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 94 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
composer.lock
composer.lock
.php_cs.cache
22 changes: 22 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$finder = PhpCsFixer\Finder::create()
//->exclude('somedir')
->in(__DIR__)
;

return PhpCsFixer\Config::create()
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'trailing_comma_in_multiline_array' => true,
'ternary_operator_spaces' => true,
'trim_array_spaces' => true,
'ordered_imports' => [
'sortAlgorithm' => 'length'
],
'ordered_class_elements' => true
])
->setFinder($finder)
;
10 changes: 5 additions & 5 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
namespace Divergence\CLI;

use Divergence\CLI\Env;
use Divergence\CLI\Controllers\CommandLineHandler;
use \League\CLImate\CLImate;
use Divergence\CLI\Controllers\Commands\Basics;
use Divergence\CLI\Controllers\Commands\Tester;
use Divergence\CLI\Controllers\Commands\Initialize;
use Divergence\CLI\Controllers\CommandLineHandler;

use \League\CLImate\CLImate;
use Divergence\CLI\Controllers\Commands\Initialize;

class Command extends CommandLineHandler
{
Expand All @@ -36,7 +36,7 @@ public static function handle()
//static::$climate->style->addCommand('orange', '38;5;208' /*'38;5;208'*/);
//static::$climate->orange('test'); exit;

switch($action = static::shiftArgs()) {
switch ($action = static::shiftArgs()) {
case 'init':
Initialize::init();
break;
Expand Down Expand Up @@ -65,4 +65,4 @@ public static function handle()
Basics::usage();
}
}
}
}
7 changes: 3 additions & 4 deletions src/Controllers/CommandLineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

abstract class CommandLineHandler
{
abstract public static function handle();

public static $_args;
abstract public static function handle();

protected static function setArgs($path = null)
{
if(!static::$_args) {
if (!static::$_args) {
static::$_args = $_SERVER['argv'];
}
}
Expand Down Expand Up @@ -53,4 +52,4 @@ protected static function unshiftArgs($string)
}
return array_unshift(static::$_args, $string);
}
}
}
14 changes: 7 additions & 7 deletions src/Controllers/Commands/Basics.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
namespace Divergence\CLI\Controllers\Commands;

use Divergence\CLI\Command;
use Divergence\CLI\Env;
use Divergence\CLI\Command;

class Basics
{
Expand All @@ -24,24 +24,24 @@ public static function status()
{
$climate = Command::getClimate();

if(!Env::$hasComposer) {
if (!Env::$hasComposer) {
$climate->backgroundYellow()->black()->out("No composer.json detected.");
return;
}

$climate->info(sprintf('Found %s',Env::$package['name']));
$climate->info(sprintf('Found %s', Env::$package['name']));

if(!Env::$isRequired && !Env::$isRequireDev) {
if (!Env::$isRequired && !Env::$isRequireDev) {
$climate->backgroundYellow()->black()->out('Did not find divergence/divergence in composer.json require');
$climate->backgroundYellow()->black()->out('Run divergence init to bootstrap your project');
return;
}

if(Env::$isRequired) {
if (Env::$isRequired) {
$climate->info('Found divergence/divergence in composer.json require');
}

if(Env::$isRequireDev) {
if (Env::$isRequireDev) {
$climate->info('Found divergence/divergence in composer.json require-dev');
}
}
Expand All @@ -67,4 +67,4 @@ public static function usage()
$climate->out("\ttest [subcommand]\t\t");
$climate->out("\t dbconfig\tChecks if DB config works. Asks you to choose a label name or provide one as the next argument.");
}
}
}
34 changes: 17 additions & 17 deletions src/Controllers/Commands/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*/
namespace Divergence\CLI\Controllers\Commands;

use Divergence\CLI\Command;
use Divergence\CLI\Env;
use PDO;
use Divergence\CLI\Env;
use Divergence\CLI\Command;

class Database
{
Expand All @@ -23,13 +23,13 @@ public static function wizard($config)
$climate->info('For your reference the config is:');

/* do not remove */
dump($config);
dump($config);

$retest = true;
do { // retest config until success or abort
$climate->inline('Testing config.......... ');
$valid = static::connectionTester($config);
if($valid) {
if ($valid) {
$climate->green('Success.');
return $config;
} else {
Expand All @@ -38,10 +38,10 @@ public static function wizard($config)
$input->defaultTo('y');
$retest = $input->confirmed();
}
} while($retest);
} while ($retest);
$input = $climate->confirm('Continue with untested config?');
$input->defaultTo('n');
if($input->confirmed()) {
if ($input->confirmed()) {
$valid = true; // human override
}
} while (!$valid);
Expand All @@ -58,34 +58,34 @@ public static function configBuilder($defaults)

$new = [];

$suggestedName = explode('/',Env::$package['name'])[1];
$suggestedName = explode('/', Env::$package['name'])[1];

// hostname or socket
$input = $climate->input(sprintf('Hostname (You can also provide a socket) <yellow>[<bold>%s</bold>]</yellow>',$defaults['host']));
$input = $climate->input(sprintf('Hostname (You can also provide a socket) <yellow>[<bold>%s</bold>]</yellow>', $defaults['host']));
$input->defaultTo($defaults['host']);
$new['host'] = $input->prompt();
if(substr($new['host'], -5) === '.sock') { // if ends with .sock treat as socket
if (substr($new['host'], -5) === '.sock') { // if ends with .sock treat as socket
$new['socket'] = $new['host'];
unset($new['host']);
}

// database name
$input = $climate->input(sprintf('Database name <yellow>[<bold>%s</bold>]</yellow>',$suggestedName));
$input = $climate->input(sprintf('Database name <yellow>[<bold>%s</bold>]</yellow>', $suggestedName));
$input->defaultTo($suggestedName);
$new['database'] = $input->prompt();

// database username
$input = $climate->input(sprintf('Database username <yellow>[<bold>%s</bold>]</yellow>',$suggestedName));
$input = $climate->input(sprintf('Database username <yellow>[<bold>%s</bold>]</yellow>', $suggestedName));
$input->defaultTo($suggestedName);
$new['username'] = $input->prompt();

// database password
$input = $climate->input('Database password: ');
$new['password'] = $input->prompt();
if(!$new['password']) {
if (!$new['password']) {
$input = $climate->confirm('Generate one?');
$input->defaultTo('y');
if($input->confirmed()) {
if ($input->confirmed()) {
$new['password'] = static::createPassword();
}
}
Expand Down Expand Up @@ -115,13 +115,13 @@ public static function connectionTester($config)
/*
* Uses ascii table chars decimal 33 (!) -> 126 (~)
* covers basic symbols and letters
*/
*/
public static function createPassword($length=20)
{
$password = '';
while(strlen($password)<$length) {
$password .= chr(mt_rand(33,126));
while (strlen($password)<$length) {
$password .= chr(mt_rand(33, 126));
}
return $password;
}
}
}
Loading

0 comments on commit 1261887

Please sign in to comment.