-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs: #533 Includes testing suite changes done in "develop" Co-authored-by: Ben Thomson <git@alfreido.com>
- Loading branch information
Luke Towers
and
Ben Thomson
committed
Nov 20, 2020
1 parent
425b9f5
commit 16d8346
Showing
15 changed files
with
542 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
if (empty($argv[1])) { | ||
echo 'You must provide a base branch to check this PR against.'; | ||
echo "\n"; | ||
exit(1); | ||
} | ||
|
||
// Get a changelist of files from Git for this PR. | ||
$fileList = shell_exec('git diff --name-only --diff-filter=ACMR origin/' . $argv[1] . ' HEAD'); | ||
$files = array_filter(explode("\n", $fileList)); | ||
|
||
foreach ($files as &$file) { | ||
if (strpos($file, ' ') !== false) { | ||
$file = str_replace(' ', '\\ ', $file); | ||
} | ||
} | ||
|
||
// Run all changed files through the PHPCS code sniffer and generate a CSV report | ||
$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files)); | ||
$lines = array_map(function ($row) { | ||
return array_map(function ($column) { | ||
return trim($column, '"'); | ||
}, explode(',', $row)); | ||
}, array_filter(explode("\n", $csv))); | ||
|
||
// Remove header row | ||
array_shift($lines); | ||
|
||
if (!count($lines)) { | ||
echo "\e[0;32mFound no issues with code quality.\e[0m"; | ||
echo "\n"; | ||
exit(0); | ||
} else { | ||
// Group errors by file | ||
$files = []; | ||
|
||
foreach ($lines as $line) { | ||
$filename = str_replace(dirname(dirname(dirname(__DIR__))), '', $line[0]); | ||
|
||
if (empty($files[$filename])) { | ||
$files[$filename] = []; | ||
} | ||
|
||
$files[$filename][] = [ | ||
'warning' => ($line[3] === 'warning'), | ||
'message' => $line[4], | ||
'line' => $line[1], | ||
]; | ||
} | ||
|
||
// Render report | ||
echo "\e[0;31mFound " | ||
. ((count($lines) === 1) | ||
? '1 issue' | ||
: count($lines) . ' issues') | ||
. " with code quality.\e[0m"; | ||
echo "\n"; | ||
|
||
foreach ($files as $file => $errors) { | ||
echo "\n"; | ||
echo "\e[1;37m" . str_replace('"', '', $file) . "\e[0m"; | ||
echo "\n\n"; | ||
|
||
foreach ($errors as $error) { | ||
echo "\e[2m" . str_pad(' L' . $error['line'], 7) . " | \e[0m"; | ||
if ($error['warning'] === false) { | ||
echo "\e[0;31mERR:\e[0m "; | ||
} else { | ||
echo "\e[1;33mWARN:\e[0m "; | ||
} | ||
echo $error['message']; | ||
echo "\n"; | ||
} | ||
} | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
if (empty($argv[1])) { | ||
echo 'You must provide a commit SHA to check.'; | ||
echo "\n"; | ||
exit(1); | ||
} | ||
|
||
// Get a changelist of files from Git for this push. | ||
$fileList = shell_exec('git show --name-only --pretty="" --diff-filter=ACMR ' . $argv[1]); | ||
$files = array_filter(explode("\n", $fileList)); | ||
|
||
foreach ($files as &$file) { | ||
if (strpos($file, ' ') !== false) { | ||
$file = str_replace(' ', '\\ ', $file); | ||
} | ||
} | ||
|
||
// Run all changed files through the PHPCS code sniffer and generate a CSV report | ||
$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files)); | ||
$lines = array_map(function ($row) { | ||
return array_map(function ($column) { | ||
return trim($column, '"'); | ||
}, explode(',', $row)); | ||
}, array_filter(explode("\n", $csv))); | ||
|
||
// Remove header row | ||
array_shift($lines); | ||
|
||
if (!count($lines)) { | ||
echo "\e[0;32mFound no issues with code quality.\e[0m"; | ||
echo "\n"; | ||
exit(0); | ||
} else { | ||
// Group errors by file | ||
$files = []; | ||
|
||
foreach ($lines as $line) { | ||
$filename = str_replace(dirname(dirname(dirname(__DIR__))), '', $line[0]); | ||
|
||
if (empty($files[$filename])) { | ||
$files[$filename] = []; | ||
} | ||
|
||
$files[$filename][] = [ | ||
'warning' => ($line[3] === 'warning'), | ||
'message' => $line[4], | ||
'line' => $line[1], | ||
]; | ||
} | ||
|
||
// Render report | ||
echo "\e[0;31mFound " | ||
. ((count($lines) === 1) | ||
? '1 issue' | ||
: count($lines) . ' issues') | ||
. " with code quality.\e[0m"; | ||
echo "\n"; | ||
|
||
foreach ($files as $file => $errors) { | ||
echo "\n"; | ||
echo "\e[1;37m" . str_replace('"', '', $file) . "\e[0m"; | ||
echo "\n\n"; | ||
|
||
foreach ($errors as $error) { | ||
echo "\e[2m" . str_pad(' L' . $error['line'], 7) . " | \e[0m"; | ||
if ($error['warning'] === false) { | ||
echo "\e[0;31mERR:\e[0m "; | ||
} else { | ||
echo "\e[1;33mWARN:\e[0m "; | ||
} | ||
echo $error['message']; | ||
echo "\n"; | ||
} | ||
} | ||
exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php namespace October\Rain\Database\Concerns; | ||
|
||
use October\Rain\Support\Str; | ||
|
||
trait GuardsAttributes | ||
{ | ||
/** | ||
* Determine if the given key is guarded. | ||
* | ||
* This is an override of https://github.com/laravel/framework/commit/897d107775737a958dbd0b2f3ea37877c7526371 | ||
* and allows fields that don't exist in the database to be filled if they aren't specified as "guarded", under | ||
* the pretense that they are handled in a special manner - ie. in the `beforeSave` event. | ||
* | ||
* @param string $key | ||
* @return bool | ||
*/ | ||
public function isGuarded($key) | ||
{ | ||
$guarded = $this->getGuarded(); | ||
// Nothing's guarded so just return early | ||
if (empty($guarded) || $guarded === ['*']) { | ||
return false; | ||
} | ||
// Normalize the variables for comparison | ||
$key = trim(strtolower($key)); | ||
$guarded = array_map(function ($column) { | ||
return trim(strtolower($column)); | ||
}, $guarded); | ||
|
||
// JSON columns are tricksy, we only guard base level columns though | ||
if (strpos($key, '->') !== false) { | ||
$key = Str::before($key, '->'); | ||
} | ||
|
||
return in_array($key, $guarded); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.