Skip to content

Commit

Permalink
PSR-12 + action (barryvdh#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Aug 16, 2020
1 parent 5d11919 commit 51c8ea3
Show file tree
Hide file tree
Showing 46 changed files with 308 additions and 186 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,36 @@ jobs:
- name: Execute Unit Tests
run: composer test

fix-style:
name: Fix Code Style
timeout-minutes: 15
runs-on: ubuntu-latest
env:
COMPOSER_NO_INTERACTION: 1

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
tools: composer:v2

- name: Install dependencies
run: |
composer update --prefer-dist --no-suggest --no-progress
- run: composer fix-style
continue-on-error: true

# Revert modifications so they don't get commited 💥
- run: git checkout -- composer.json

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: composer fix-style
commit_author: laravel-debugbar <laravel-debugbar@users.noreply.github.com>
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
}
},
"scripts": {
"check-style": "phpcs -p --standard=PSR12 config/ resources/ src/ tests/",
"fix-style": "phpcbf -p --standard=PSR12 config/ resources/ src/ tests/",
"check-style": "phpcs -p --standard=PSR12 config/ src/ tests/",
"fix-style": "phpcbf -p --standard=PSR12 config/ src/ tests/",
"test": "phpunit"
}
}
2 changes: 1 addition & 1 deletion config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
'timeline' => false, // Add the queries to the timeline
'explain' => [ // Show EXPLAIN output on queries
'enabled' => false,
'types' => ['SELECT'], // // workaround ['SELECT'] only. https://github.com/barryvdh/laravel-debugbar/issues/888 ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+
'types' => ['SELECT'], // Deprecated setting, is always only SELECT
],
'hints' => false, // Show hints for common mistakes
'show_copy' => false, // Show copy button next to the query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand Down Expand Up @@ -27,7 +28,7 @@ public function up()
$table->index('meta_uri');
$table->index('meta_ip');
$table->index('meta_method');
});
});
}
/**
* Reverse the migrations.
Expand Down
11 changes: 6 additions & 5 deletions src/Console/ClearCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Barryvdh\Debugbar\Console;
<?php

namespace Barryvdh\Debugbar\Console;

use DebugBar\DebugBar;
use Illuminate\Console\Command;
Expand All @@ -21,12 +23,11 @@ public function handle()
$this->debugbar->boot();

if ($storage = $this->debugbar->getStorage()) {
try
{
try {
$storage->clear();
} catch(\InvalidArgumentException $e) {
} catch (\InvalidArgumentException $e) {
// hide InvalidArgumentException if storage location does not exist
if(strpos($e->getMessage(), 'does not exist') === false) {
if (strpos($e->getMessage(), 'does not exist') === false) {
throw $e;
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/Controllers/AssetController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Barryvdh\Debugbar\Controllers;
<?php

namespace Barryvdh\Debugbar\Controllers;

use Illuminate\Http\Response;

Expand All @@ -16,7 +18,9 @@ public function js()
$content = $renderer->dumpAssetsToString('js');

$response = new Response(
$content, 200, [
$content,
200,
[
'Content-Type' => 'text/javascript',
]
);
Expand All @@ -36,7 +40,9 @@ public function css()
$content = $renderer->dumpAssetsToString('css');

$response = new Response(
$content, 200, [
$content,
200,
[
'Content-Type' => 'text/css',
]
);
Expand Down
9 changes: 6 additions & 3 deletions src/Controllers/BaseController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php namespace Barryvdh\Debugbar\Controllers;
<?php

namespace Barryvdh\Debugbar\Controllers;

use Barryvdh\Debugbar\LaravelDebugbar;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Laravel\Telescope\Telescope;

// phpcs:ignoreFile
if (class_exists('Illuminate\Routing\Controller')) {

class BaseController extends Controller
Expand All @@ -15,7 +18,7 @@ public function __construct(Request $request, LaravelDebugbar $debugbar)
{
$this->debugbar = $debugbar;

if ($request->hasSession()){
if ($request->hasSession()) {
$request->session()->reflash();
}

Expand All @@ -38,7 +41,7 @@ public function __construct(Request $request, LaravelDebugbar $debugbar)
{
$this->debugbar = $debugbar;

if ($request->hasSession()){
if ($request->hasSession()) {
$request->session()->reflash();
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Controllers/CacheController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Barryvdh\Debugbar\Controllers;
<?php

namespace Barryvdh\Debugbar\Controllers;

use Illuminate\Http\Response;

Expand All @@ -23,5 +25,4 @@ public function delete($key, $tags = '')

return response()->json(compact('success'));
}

}
8 changes: 6 additions & 2 deletions src/Controllers/OpenHandlerController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Barryvdh\Debugbar\Controllers;
<?php

namespace Barryvdh\Debugbar\Controllers;

use Barryvdh\Debugbar\Support\Clockwork\Converter;
use DebugBar\OpenHandler;
Expand All @@ -13,7 +15,9 @@ public function handle()
$data = $openHandler->handle(null, false, false);

return new Response(
$data, 200, [
$data,
200,
[
'Content-Type' => 'application/json'
]
);
Expand Down
4 changes: 3 additions & 1 deletion src/Controllers/TelescopeController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Barryvdh\Debugbar\Controllers;
<?php

namespace Barryvdh\Debugbar\Controllers;

use Barryvdh\Debugbar\Support\Clockwork\Converter;
use DebugBar\OpenHandler;
Expand Down
3 changes: 2 additions & 1 deletion src/DataCollector/CacheCollector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

use DebugBar\DataCollector\TimeDataCollector;
Expand All @@ -22,7 +23,7 @@ class CacheCollector extends TimeDataCollector
KeyForgotten::class => 'forgotten',
];

public function __construct($requestStartTime = null, $collectValues)
public function __construct($requestStartTime, $collectValues)
{
parent::__construct();

Expand Down
5 changes: 3 additions & 2 deletions src/DataCollector/EventCollector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

use Barryvdh\Debugbar\DataFormatter\SimpleFormatter;
Expand Down Expand Up @@ -29,7 +30,6 @@ public function onWildcardEvent($name = null, $data = [])

// Find all listeners for the current event
foreach ($this->events->getListeners($name) as $i => $listener) {

// Check if it's an object + method name
if (is_array($listener) && count($listener) > 1 && is_object($listener[0])) {
list($class, $method) = $listener;
Expand All @@ -53,7 +53,8 @@ public function onWildcardEvent($name = null, $data = [])

// Format the closure to a readable format
$filename = ltrim(str_replace(base_path(), '', $reflector->getFileName()), '/');
$listener = $reflector->getName() . ' (' . $filename . ':' . $reflector->getStartLine() . '-' . $reflector->getEndLine() . ')';
$lines = $reflector->getStartLine() . '-' . $reflector->getEndLine();
$listener = $reflector->getName() . ' (' . $filename . ':' . $lines . ')';
} else {
// Not sure if this is possible, but to prevent edge cases
$listener = $this->getDataFormatter()->formatVar($listener);
Expand Down
3 changes: 2 additions & 1 deletion src/DataCollector/FilesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function collect()
foreach ($files as $file) {
// Skip the files from Debugbar, they are only loaded for Debugging and confuse the output.
// Of course some files are stil always loaded (ServiceProvider, Facade etc)
if (strpos($file, 'vendor/maximebf/debugbar/src') !== false || strpos(
if (
strpos($file, 'vendor/maximebf/debugbar/src') !== false || strpos(
$file,
'vendor/barryvdh/laravel-debugbar/src'
) !== false
Expand Down
4 changes: 2 additions & 2 deletions src/DataCollector/GateCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function __construct(Gate $gate)
{
parent::__construct('gate');
$this->setDataFormatter(new SimpleFormatter());
$gate->after(function ($user = null, $ability, $result, $arguments = []) {
$gate->after(function ($user, $ability, $result, $arguments = []) {
$this->addCheck($user, $ability, $result, $arguments);
});
}

public function addCheck($user = null, $ability, $result, $arguments = [])
public function addCheck($user, $ability, $result, $arguments = [])
{
$userKey = 'user';
$userId = null;
Expand Down
4 changes: 2 additions & 2 deletions src/DataCollector/LivewireCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class LivewireCollector extends DataCollector implements DataCollectorInterface,
public function __construct(Request $request)
{
// Listen to Livewire views
Livewire::listen('view:render', function(View $view) use ($request) {
Livewire::listen('view:render', function (View $view) use ($request) {
/** @var \Livewire\Component $component */
$component = $view->getData()['_instance'];

// Create an unique name for each compoent
$key = $component->getName() . ' #' .$component->id;
$key = $component->getName() . ' #' . $component->id;

$data = [
'data' => $component->getPublicPropertiesDefinedBySubClass(),
Expand Down
1 change: 1 addition & 0 deletions src/DataCollector/LogsCollector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

use DebugBar\DataCollector\MessagesCollector;
Expand Down
6 changes: 2 additions & 4 deletions src/DataCollector/MultiAuthCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Illuminate\Support\Str;
use Illuminate\Contracts\Support\Arrayable;


/**
* Collector for Laravel's Auth provider
*/
Expand Down Expand Up @@ -55,13 +54,13 @@ public function collect()
];
$names = '';

foreach($this->guards as $guardName => $config) {
foreach ($this->guards as $guardName => $config) {
try {
$guard = $this->auth->guard($guardName);
if ($this->hasUser($guard)) {
$user = $guard->user();

if(!is_null($user)) {
if (!is_null($user)) {
$data['guards'][$guardName] = $this->getUserInformation($user);
$names .= $guardName . ": " . $data['guards'][$guardName]['name'] . ', ';
}
Expand Down Expand Up @@ -166,5 +165,4 @@ public function getWidgets()

return $widgets;
}

}
1 change: 1 addition & 0 deletions src/DataCollector/PhpInfoCollector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Barryvdh\Debugbar\DataCollector;

use DebugBar\DataCollector\PhpInfoCollector as DebugBarPhpInfoCollector;
Expand Down
16 changes: 10 additions & 6 deletions src/DataCollector/QueryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function addQuery($query, $bindings, $time, $connection)
$bindings = $connection->prepareBindings($bindings);

// Run EXPLAIN on this query (if needed)
if ($this->explainQuery && $pdo && preg_match('/^\s*('.implode('|', $this->explainTypes).') /i', $query)) {
if ($this->explainQuery && $pdo && preg_match('/^\s*(' . implode('|', $this->explainTypes) . ') /i', $query)) {
$statement = $pdo->prepare('EXPLAIN ' . $query);
$statement->execute($bindings);
$explainResults = $statement->fetchAll(\PDO::FETCH_CLASS);
Expand Down Expand Up @@ -210,6 +210,7 @@ protected function emulateQuote($value)
*/
protected function performQueryAnalysis($query)
{
// @codingStandardsIgnoreStart
$hints = [];
if (preg_match('/^\\s*SELECT\\s*`?[a-zA-Z0-9]*`?\\.?\\*/i', $query)) {
$hints[] = 'Use <code>SELECT *</code> only if you need all columns from table';
Expand All @@ -229,10 +230,12 @@ protected function performQueryAnalysis($query)
$hints[] = '<code>LIMIT</code> without <code>ORDER BY</code> causes non-deterministic results, depending on the query execution plan';
}
if (preg_match('/LIKE\\s[\'"](%.*?)[\'"]/i', $query, $matches)) {
$hints[] = 'An argument has a leading wildcard character: <code>' . $matches[1]. '</code>.
$hints[] = 'An argument has a leading wildcard character: <code>' . $matches[1] . '</code>.
The predicate with this argument is not sargable and cannot use an index if one exists.';
}
return $hints;

// @codingStandardsIgnoreEnd
}

/**
Expand Down Expand Up @@ -275,7 +278,8 @@ protected function parseTrace($index, array $trace)
return $frame;
}

if (isset($trace['class']) &&
if (
isset($trace['class']) &&
isset($trace['file']) &&
!$this->fileIsInExcludedPath($trace['file'])
) {
Expand Down Expand Up @@ -369,7 +373,7 @@ protected function findViewFromHash($hash)
$this->reflection['viewfinderViews'] = $property;
}

foreach ($property->getValue($finder) as $name => $path){
foreach ($property->getValue($finder) as $name => $path) {
if (sha1($path) == $hash || md5($path) == $hash) {
return $name;
}
Expand Down Expand Up @@ -476,9 +480,9 @@ public function collect()
];

//Add the results from the explain as new rows
foreach($query['explain'] as $explain){
foreach ($query['explain'] as $explain) {
$statements[] = [
'sql' => ' - EXPLAIN #' . $explain->id . ': `' . $explain->table . '` (' . $explain->select_type . ')',
'sql' => " - EXPLAIN # {$explain->id}: `{$explain->table}` ({$explain->select_type})",
'type' => 'explain',
'params' => $explain,
'row_count' => $explain->rows,
Expand Down
Loading

0 comments on commit 51c8ea3

Please sign in to comment.