Skip to content

Commit

Permalink
PSR12
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Sep 11, 2020
1 parent be09bd7 commit 70675af
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 123 deletions.
9 changes: 9 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>PHPCS configuration file.</description>
<file>src</file>
<exclude-pattern>*/exclude/*</exclude-pattern>
<!-- ignore warnings and display ERRORS only -->
<arg value="np"/>
<rule ref="PSR12"/>
</ruleset>
101 changes: 50 additions & 51 deletions src/Console/LaraLensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@

class LaraLensCommand extends Command
{
private const TABLE_STYLES ='default|borderless|compact|symfony-style-guide|box|box-double';
private const DEFAULT_STYLE='box-double';
private const TABLE_STYLES = 'default|borderless|compact|symfony-style-guide|box|box-double';
private const DEFAULT_STYLE = 'box-double';
private const DEFAULT_PATH = '';
protected $styleTable=self::DEFAULT_STYLE;
protected $styleTable = self::DEFAULT_STYLE;
protected $signature = 'laralens:diagnostic
{op=overview : What you want to see, overview or allconfigs (overview|allconfigs)}
{--table=users : name of the table, default users}
{--column-sort=created_at : column name used for sorting}
{--url-path='.self::DEFAULT_PATH.' : default path for checking URL}
{--url-path=' . self::DEFAULT_PATH . ' : default path for checking URL}
{--show=*all : show (all|config|runtime|connection|database|migration)}
{--width-label='.self::DEFAULT_WIDTH.' : width of column for label}
{--width-value='.self::DEFAULT_WIDTH.' : width of column for value}
{--style='.self::DEFAULT_STYLE.' : style of the output table ('.self::TABLE_STYLES.')}
{--width-label=' . self::DEFAULT_WIDTH . ' : width of column for label}
{--width-value=' . self::DEFAULT_WIDTH . ' : width of column for value}
{--style=' . self::DEFAULT_STYLE . ' : style of the output table (' . self::TABLE_STYLES . ')}
{--skip-database : skip database check like connection and migration (if your laravel app doesn\'t need Database)}
';

protected $description = 'Show some application configurations.';

private const DEFAULT_WIDTH=36;
protected $widthLabel=self::DEFAULT_WIDTH;
protected $widthValue=self::DEFAULT_WIDTH;
private const DEFAULT_WIDTH = 36;
protected $widthLabel = self::DEFAULT_WIDTH;
protected $widthValue = self::DEFAULT_WIDTH;

protected $urlPath = self::DEFAULT_PATH;

public const OPTION_SHOW_NONE= 0b0000000;
public const OPTION_SHOW_CONFIGS= 0b0000001;
public const OPTION_SHOW_RUNTIMECONFIGS= 0b00000010;
public const OPTION_SHOW_CONNECTIONS= 0b00000100;
public const OPTION_SHOW_DATABASE= 0b00001000;
public const OPTION_SHOW_MIGRATION= 0b00010000;
public const OPTION_SHOW_NONE = 0b0000000;
public const OPTION_SHOW_CONFIGS = 0b0000001;
public const OPTION_SHOW_RUNTIMECONFIGS = 0b00000010;
public const OPTION_SHOW_CONNECTIONS = 0b00000100;
public const OPTION_SHOW_DATABASE = 0b00001000;
public const OPTION_SHOW_MIGRATION = 0b00010000;
public const OPTION_SHOW_ALL = 0b00011111;

private function allConfigs()
Expand All @@ -50,17 +50,17 @@ private function allConfigs()
private function formatCell($string, $width)
{
$retVal = "";
if (strlen($string)> $width) {
if (strlen($string) > $width) {
$retVal = Str::limit($string, $width, '');
} elseif (strlen($string)< $width) {
} elseif (strlen($string) < $width) {
$retVal = str_pad($string, $width);
} else {
$retVal = $string;
}
return $retVal;
}

private function print_output(array $headers, array $rows)
private function printOutput(array $headers, array $rows)
{
$rowsTable = [];
$rowsLine = [];
Expand Down Expand Up @@ -88,12 +88,12 @@ private function print_output(array $headers, array $rows)
* 'box-double'
*/
$this->table($headers, $rowsTable, $this->styleTable);
foreach ($rowsLine as $key =>$line) {
foreach ($rowsLine as $key => $line) {
$label = Arr::get($line, "label", "");
$value = Arr::get($line, "value", "");
$lineType = Arr::get($row, "lineType", ResultLens::LINE_TYPE_DEFAULT);
if ($label != "") {
$this->info($label.":");
$this->info($label . ":");
}
if ($lineType === ResultLens::LINE_TYPE_ERROR) {
$this->error($value);
Expand All @@ -105,23 +105,23 @@ private function print_output(array $headers, array $rows)
}
}

private function alert_green($string)
private function alertGreen($string)
{
$length = Str::length(strip_tags($string)) + 12;
$this->info(str_repeat('*', $length));
$this->info('* '.$string.' *');
$this->info('* ' . $string . ' *');
$this->info(str_repeat('*', $length));
$this->output->newLine();
}

private function print_checks(array $rows)
private function printChecks(array $rows)
{
if (sizeof($rows) == 0) {
$this->alert_green("CHECK: everything looks good");
$this->alertGreen("CHECK: everything looks good");
} else {
$this->alert("CHECK: issues found");
}
$idx=0;
$idx = 0;
foreach ($rows as $key => $row) {
$label = Arr::get($row, "label", "");
$value = Arr::get($row, "value", "");
Expand All @@ -130,7 +130,7 @@ private function print_checks(array $rows)
if ($label != "" & ($lineType === ResultLens::LINE_TYPE_ERROR | ResultLens::isMessageLine($lineType))) {
$idx++;
$this->warn("--- " . $idx . " ------------------");
$this->warn("*** ". $label);
$this->warn("*** " . $label);
}
if ($lineType === ResultLens::LINE_TYPE_ERROR) {
$this->error($value);
Expand All @@ -144,30 +144,30 @@ private function print_checks(array $rows)
}
}

private function overview($checkTable = "users", $columnSorting = "created_at", $show= self::OPTION_SHOW_ALL)
private function overview($checkTable = "users", $columnSorting = "created_at", $show = self::OPTION_SHOW_ALL)
{
$ll = new LaraLens();
if ($show & self::OPTION_SHOW_CONFIGS) {
$output = $ll->getConfigs();
$this->print_output(["Config key via config()", "Values"], $output->toArray());
$this->printOutput(["Config key via config()", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) {
$output = $ll->getRuntimeConfigs();
$this->print_output(["Runtime Configs", "Values"], $output->toArray());
$this->printOutput(["Runtime Configs", "Values"], $output->toArray());
$output = $ll->checkServerRequirements();
$this->print_output(["Laravel Requirements", "Values"], $output->toArray());
$this->printOutput(["Laravel Requirements", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) {
$output = $ll->checkFiles();
$this->print_output(["Check files", "Values"], $output->toArray());
$this->printOutput(["Check files", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_CONNECTIONS) {
$output = $ll->getConnections($this->urlPath);
$this->print_output(["Connections", "Values"], $output->toArray());
$this->printOutput(["Connections", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_DATABASE) {
$output = $ll->getDatabase($checkTable, $columnSorting);
$this->print_output(["Database", "Values"], $output->toArray());
$this->printOutput(["Database", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_MIGRATION) {
try {
Expand All @@ -183,10 +183,10 @@ private function overview($checkTable = "users", $columnSorting = "created_at",
$e->getMessage(),
"Check the Database configuration"
);
$this->print_output(["Migration" , "result"], $r->toArray());
$this->printOutput(["Migration" , "result"], $r->toArray());
}
}
$this->print_checks($ll->checksBag->toArray());
$this->printChecks($ll->checksBag->toArray());
}


Expand All @@ -201,10 +201,10 @@ public function handle()
$this->styleTable = self::DEFAULT_STYLE;
}
$columnSorting = $this->option("column-sort");
$showOptions= $this->option("show");
$showOptions = $this->option("show");

if (is_array($showOptions)) {
if (count($showOptions) >0) {
if (count($showOptions) > 0) {
$show = self::OPTION_SHOW_NONE;
if (in_array("all", $showOptions)) {
$show = self::OPTION_SHOW_ALL;
Expand All @@ -219,30 +219,29 @@ public function handle()
$show = (in_array("connection", $showOptions)) ? $show | self::OPTION_SHOW_CONNECTIONS : $show ;
$show = (in_array("database", $showOptions)) ? $show | self::OPTION_SHOW_DATABASE : $show ;
$show = (in_array("migration", $showOptions)) ? $show | self::OPTION_SHOW_MIGRATION : $show ;

}
}
}

$this->widthLabel= $this->option("width-label");
$this->widthValue= $this->option("width-value");
$this->widthLabel = $this->option("width-label");
$this->widthValue = $this->option("width-value");

$this->urlPath = $this->option("url-path");
if (is_null($this->urlPath)) {
$this->urlPath = self::DEFAULT_PATH;
}

switch ($op) {
case 'overview':
$this->overview($checkTable, $columnSorting, $show);
break;
case 'allconfigs':
$this->allConfigs();
break;

default:
$this->info("What you mean? try with 'php artisan laralens:diagnostic --help'");
break;
case 'overview':
$this->overview($checkTable, $columnSorting, $show);
break;
case 'allconfigs':
$this->allConfigs();
break;

default:
$this->info("What you mean? try with 'php artisan laralens:diagnostic --help'");
break;
}
}
}
13 changes: 7 additions & 6 deletions src/LaraLensServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use HiFolks\LaraLens\Console\LaraLensCommand;
use Illuminate\Support\ServiceProvider;

use HiFolks\LaraLens\Lens\LaraLens;

class LaraLensServiceProvider extends ServiceProvider
Expand All @@ -25,8 +24,9 @@ public function boot()
if ($this->app->runningInConsole()) {
$this->publishes(
[
__DIR__.'/../config/config.php' => config_path('lara-lens.php'),
], 'config'
__DIR__ . '/../config/config.php' => config_path('lara-lens.php'),
],
'config'
);

// Publishing the views.
Expand Down Expand Up @@ -59,12 +59,13 @@ public function boot()
public function register()
{
// Automatically apply the package configuration
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'lara-lens');
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'lara-lens');

// Register the main class to use with the facade
$this->app->singleton(
'lara-lens', function () {
return new LaraLens;
'lara-lens',
function () {
return new LaraLens();
}
);
}
Expand Down
1 change: 0 additions & 1 deletion src/Lens/LaraHttp.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace HiFolks\LaraLens\Lens;

use GuzzleHttp\Client;
Expand Down
2 changes: 1 addition & 1 deletion src/Lens/LaraLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public function getCredits()
*/
public static function printBool(bool $b)
{
return $b ? "Yes": "No";
return $b ? "Yes" : "No";
}
}
3 changes: 2 additions & 1 deletion src/Lens/Objects/LaraHttpResponse.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace HiFolks\LaraLens\Lens\Objects;

use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -37,6 +38,6 @@ public function status()
*/
public function failed()
{
return ($this->response->getStatusCode()>= 400);
return ($this->response->getStatusCode() >= 400);
}
}
15 changes: 8 additions & 7 deletions src/Lens/Traits/ConfigLens.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace HiFolks\LaraLens\Lens\Traits;

use App;
Expand All @@ -11,7 +12,7 @@ public function getConfigsDatabaseFromEnv(ResultLens $results = null)
if (is_null($results)) {
$results = new ResultLens();
}
$configKeys=[
$configKeys = [
"DB_HOST",
"DB_DATABASE",
"DB_USERNAME",
Expand All @@ -20,7 +21,7 @@ public function getConfigsDatabaseFromEnv(ResultLens $results = null)
];
foreach ($configKeys as $key => $value) {
$results->add(
".env ".$value,
".env " . $value,
env($value)
);
}
Expand All @@ -32,9 +33,9 @@ public function getConfigsDatabase(ResultLens $results = null)
if (is_null($results)) {
$results = new ResultLens();
}
$configKeys=[
$configKeys = [
"database.default",
"database.connections.".config("database.default").".driver",
"database.connections." . config("database.default") . ".driver",
"database.connections." . config("database.default") . ".url",
"database.connections." . config("database.default") . ".host",
"database.connections." . config("database.default") . ".port",
Expand All @@ -43,7 +44,7 @@ public function getConfigsDatabase(ResultLens $results = null)
];
foreach ($configKeys as $key => $value) {
$results->add(
"".$value,
"" . $value,
config($value)
);
}
Expand All @@ -57,15 +58,15 @@ public function getConfigs()
"Running diagnostic",
date('Y-m-d H:i:s')
);
$configKeys=[
$configKeys = [
"app.timezone",
"app.locale",
"app.name",
"app.url",
];
foreach ($configKeys as $key => $value) {
$results->add(
"".$value,
"" . $value,
config($value)
);
}
Expand Down
Loading

0 comments on commit 70675af

Please sign in to comment.