Skip to content

Commit

Permalink
fix style with phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Sep 6, 2020
1 parent be7d98b commit 5463c79
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 128 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor
coverage
.phpunit.result.cache
.idea
.php_cs.cache
55 changes: 25 additions & 30 deletions src/Console/LaraLensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@

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 DEFAULT_PATH = "";
private const DEFAULT_PATH = '';
protected $styleTable=self::DEFAULT_STYLE;
protected $signature = 'laralens:diagnostic
{op=overview : What you want to see, overview or allconfigs (overview|allconfigs)}
Expand Down Expand Up @@ -51,11 +50,9 @@ private function allConfigs()
private function formatCell($string, $width)
{
$retVal = "";
if (strlen($string)> $width)
{
if (strlen($string)> $width) {
$retVal = Str::limit($string, $width, '');
} else if (strlen($string)< $width)
{
} elseif (strlen($string)< $width) {
$retVal = str_pad($string, $width);
} else {
$retVal = $string;
Expand All @@ -67,20 +64,18 @@ private function print_output(array $headers, array $rows)
{
$rowsTable = [];
$rowsLine = [];
foreach ($rows as $key => $row)
{
foreach ($rows as $key => $row) {
$label = Arr::get($row, "label", "");
$value = Arr::get($row, "value", "");
$isLine = Arr::get($row, "isLine", false);
$lineType = Arr::get($row, "lineType", ResultLens::LINE_TYPE_DEFAULT);

if (strlen($value) > $this->widthValue || $isLine || $lineType === ResultLens::LINE_TYPE_ERROR || $lineType === ResultLens::LINE_TYPE_WARNING ) {
if (strlen($value) > $this->widthValue || $isLine || $lineType === ResultLens::LINE_TYPE_ERROR || $lineType === ResultLens::LINE_TYPE_WARNING) {
$rowsLine[] = $row;
} else {
$row["label"] = $this->formatCell($label, $this->widthLabel);
$row["value"] = $this->formatCell($value, $this->widthValue);
$rowsTable[] = [ $row["label"], $row["value"] ];

}
}
/*
Expand All @@ -92,26 +87,26 @@ private function print_output(array $headers, array $rows)
* 'box'
* 'box-double'
*/
$this->table($headers, $rowsTable,$this->styleTable);
foreach ($rowsLine as $key =>$line)
{
$this->table($headers, $rowsTable, $this->styleTable);
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.":");
}
if ($lineType === ResultLens::LINE_TYPE_ERROR ) {
if ($lineType === ResultLens::LINE_TYPE_ERROR) {
$this->error($value);
}elseif ($lineType === ResultLens::LINE_TYPE_WARNING) {
} elseif ($lineType === ResultLens::LINE_TYPE_WARNING) {
$this->warn($value);
} else {
$this->line($value);
}
}
}

private function alert_green($string) {
private function alert_green($string)
{
$length = Str::length(strip_tags($string)) + 12;
$this->info(str_repeat('*', $length));
$this->info('* '.$string.' *');
Expand All @@ -127,22 +122,21 @@ private function print_checks(array $rows)
$this->alert("CHECK: issues found");
}
$idx=0;
foreach ($rows as $key => $row)
{
foreach ($rows as $key => $row) {
$label = Arr::get($row, "label", "");
$value = Arr::get($row, "value", "");
$isLine = Arr::get($row, "isLine", false);
$lineType = Arr::get($row, "lineType", ResultLens::LINE_TYPE_DEFAULT);
if ($label != "" & ( $lineType === ResultLens::LINE_TYPE_ERROR | ResultLens::isMessageLine($lineType) ) ) {
if ($label != "" & ($lineType === ResultLens::LINE_TYPE_ERROR | ResultLens::isMessageLine($lineType))) {
$idx++;
$this->warn( "--- " . $idx . " ------------------");
$this->warn( "*** ". $label);
$this->warn("--- " . $idx . " ------------------");
$this->warn("*** ". $label);
}
if ($lineType === ResultLens::LINE_TYPE_ERROR) {
$this->error($value);
}elseif ($lineType === ResultLens::LINE_TYPE_WARNING) {
} elseif ($lineType === ResultLens::LINE_TYPE_WARNING) {
$this->warn($value);
}elseif ($lineType === ResultLens::LINE_TYPE_INFO) {
} elseif ($lineType === ResultLens::LINE_TYPE_INFO) {
$this->info($value);
} else {
$this->comment($value);
Expand All @@ -153,8 +147,7 @@ private function print_checks(array $rows)
private function overview($checkTable = "users", $columnSorting = "created_at", $show= self::OPTION_SHOW_ALL)
{
$ll = new LaraLens();
if ($show & self::OPTION_SHOW_CONFIGS)
{
if ($show & self::OPTION_SHOW_CONFIGS) {
$output = $ll->getConfigs();
$this->print_output(["Config key via config()", "Values"], $output->toArray());
}
Expand All @@ -181,17 +174,19 @@ private function overview($checkTable = "users", $columnSorting = "created_at",
$this->call('migrate:status');
} catch (\Exception $e) {
$r = new ResultLens();
$r->add("Check migrate status",
"Error in check migration");
$r->add(
"Check migrate status",
"Error in check migration"
);
$ll->checksBag->addErrorAndHint(
"Migration status",
"Migration status",
$e->getMessage(),
"Check the Database configuration"
);
$this->print_output(["Migration" , "result"], $r->toArray());
}
}
$this->print_checks( $ll->checksBag->toArray() );
$this->print_checks($ll->checksBag->toArray());
}


Expand Down Expand Up @@ -224,7 +219,7 @@ public function handle()
$this->widthValue= $this->option("width-value");

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

Expand Down
3 changes: 0 additions & 3 deletions src/LaraLensFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Illuminate\Support\Facades\Facade;

/**
* @see \HiFolks\LaraLens\Skeleton\SkeletonClass
*/
class LaraLensFacade extends Facade
{
/**
Expand Down
9 changes: 6 additions & 3 deletions src/Lens/LaraHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@

namespace HiFolks\LaraLens\Lens;


use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use HiFolks\LaraLens\Lens\Objects\LaraHttpResponse;


class LaraHttp
{

public static function get($url)
{
$client = new Client();
$response = new LaraHttpResponse($client->get($url));
try {
$response = new LaraHttpResponse($client->get($url));
} catch (GuzzleException $e) {
$response = null;
}
return $response;
}
}
15 changes: 4 additions & 11 deletions src/Lens/LaraLens.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<?php

namespace HiFolks\LaraLens\Lens;
use App;

use HiFolks\LaraLens\Lens\Traits\ConfigLens;
use HiFolks\LaraLens\Lens\Traits\DatabaseLens;
use HiFolks\LaraLens\Lens\Traits\FilesystemLens;
use HiFolks\LaraLens\Lens\Traits\HttpConnectionLens;
use HiFolks\LaraLens\Lens\Traits\RuntimeLens;
use HiFolks\LaraLens\ResultLens;


class LaraLens
{
use DatabaseLens;
use ConfigLens;
use HttpConnectionLens;
use RuntimeLens;
USE FilesystemLens;
use FilesystemLens;

/**
* @var ResultLens
Expand Down Expand Up @@ -48,14 +47,8 @@ public function getCredits()
* @param bool $b
* @return string
*/
public static function printBool(bool $b) {
public static function printBool(bool $b)
{
return $b ? "Yes": "No";
}







}
23 changes: 17 additions & 6 deletions src/Lens/Objects/LaraHttpResponse.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
namespace HiFolks\LaraLens\Lens\Objects;

use Psr\Http\Message\ResponseInterface;

class LaraHttpResponse {
class LaraHttpResponse
{
/**
* @var ResponseInterface
*/
Expand All @@ -16,13 +18,22 @@ public function __construct(ResponseInterface $r)
{
$this->response = $r;
}
public function status() {
$this->response->getStatusCode();
}

/**
* Return the Http response status code.
* @return int
*/
public function status()
{
return $this->response->getStatusCode();
}

public function failed() {
/**
* Return true if the status code of the HTTP response is an error
* @return bool
*/
public function failed()
{
return ($this->response->getStatusCode()>= 400);
}

}
8 changes: 4 additions & 4 deletions src/Lens/Traits/ConfigLens.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

trait ConfigLens
{
public function getConfigsDatabaseFromEnv(ResultLens $results = null) {
public function getConfigsDatabaseFromEnv(ResultLens $results = null)
{
if (is_null($results)) {
$results = new ResultLens();
}
Expand All @@ -26,7 +27,8 @@ public function getConfigsDatabaseFromEnv(ResultLens $results = null) {
return $results;
}

public function getConfigsDatabase(ResultLens $results = null) {
public function getConfigsDatabase(ResultLens $results = null)
{
if (is_null($results)) {
$results = new ResultLens();
}
Expand Down Expand Up @@ -70,6 +72,4 @@ public function getConfigs()
$results = $this->getConfigsDatabase($results);
return $results;
}


}
Loading

0 comments on commit 5463c79

Please sign in to comment.