Add PHP_CodeSniffer, lint code
This commit is contained in:
parent
172131e1e6
commit
ddf235a61b
8 changed files with 188 additions and 68 deletions
|
@ -29,8 +29,12 @@ class SendDigest extends Command
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if (!$this->option('daily') && !$this->option('weekly') && !$this->option('fortnightly') && !$this->option('monthly')) {
|
if (!$this->option('daily') &&
|
||||||
|
!$this->option('weekly') &&
|
||||||
|
!$this->option('fortnightly') &&
|
||||||
|
!$this->option('monthly')
|
||||||
|
) {
|
||||||
$this->error('No schedule specified.');
|
$this->error('No schedule specified.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,26 +18,28 @@ class Kernel extends ConsoleKernel
|
||||||
{
|
{
|
||||||
$schedule->command('digest:send --daily')
|
$schedule->command('digest:send --daily')
|
||||||
->daily()
|
->daily()
|
||||||
->onFailure(function() {
|
->onFailure(function () {
|
||||||
Log::error("Daily email digest send failed");
|
Log::error("Daily email digest send failed");
|
||||||
});
|
});
|
||||||
|
|
||||||
$schedule->command('digest:send --weekly')
|
$schedule->command('digest:send --weekly')
|
||||||
->weekly()
|
->weekly()
|
||||||
->onFailure(function() {
|
->onFailure(function () {
|
||||||
Log::error("Weekly email digest send failed");
|
Log::error("Weekly email digest send failed");
|
||||||
});
|
});
|
||||||
|
|
||||||
$schedule->command('digest:send --fortnightly')
|
$schedule->command('digest:send --fortnightly')
|
||||||
->weeklyOn(5, '00:01')
|
->weeklyOn(5, '00:01')
|
||||||
->when(function() { return (time() / 604800 % 2); })
|
->when(function () {
|
||||||
->onFailure(function() {
|
return (time() / 604800 % 2);
|
||||||
|
})
|
||||||
|
->onFailure(function () {
|
||||||
Log::error("Fortnightly email digest send failed");
|
Log::error("Fortnightly email digest send failed");
|
||||||
});
|
});
|
||||||
|
|
||||||
$schedule->command('digest:send --monthly')
|
$schedule->command('digest:send --monthly')
|
||||||
->monthly()
|
->monthly()
|
||||||
->onFailure(function() {
|
->onFailure(function () {
|
||||||
Log::error("Monthly email digest send failed");
|
Log::error("Monthly email digest send failed");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ class TrackerController extends Controller
|
||||||
*
|
*
|
||||||
* @return \Illuminate\View\View
|
* @return \Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function show_past_trips_list() {
|
public function show_past_trips_list()
|
||||||
|
{
|
||||||
return view('past-trips');
|
return view('past-trips');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +30,12 @@ class TrackerController extends Controller
|
||||||
* @param string? $tripId
|
* @param string? $tripId
|
||||||
* @return \Illuminate\View\View
|
* @return \Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function show_trip(Request $request, string $tripId = null) {
|
public function show_trip(Request $request, string $tripId = null)
|
||||||
|
{
|
||||||
$tripId = $tripId ?? config('app.current_trip_id');
|
$tripId = $tripId ?? config('app.current_trip_id');
|
||||||
if (!$tripId) return view('no-trip');
|
if (!$tripId) {
|
||||||
|
return view('no-trip');
|
||||||
|
}
|
||||||
|
|
||||||
$viewMode = $request->input('show', null);
|
$viewMode = $request->input('show', null);
|
||||||
$fromCheckin = $request->input('from', null);
|
$fromCheckin = $request->input('from', null);
|
||||||
|
@ -42,28 +46,28 @@ class TrackerController extends Controller
|
||||||
|
|
||||||
if ($fromCheckin) {
|
if ($fromCheckin) {
|
||||||
$tripData->checkins = array_filter(
|
$tripData->checkins = array_filter(
|
||||||
$tripData->checkins,
|
$tripData->checkins,
|
||||||
function($key) use ($fromCheckin) {
|
function ($key) use ($fromCheckin) {
|
||||||
return $key >= $fromCheckin;
|
return $key >= $fromCheckin;
|
||||||
},
|
},
|
||||||
ARRAY_FILTER_USE_KEY
|
ARRAY_FILTER_USE_KEY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($toCheckin) {
|
if ($toCheckin) {
|
||||||
$tripData->checkins = array_filter(
|
$tripData->checkins = array_filter(
|
||||||
$tripData->checkins,
|
$tripData->checkins,
|
||||||
function($key) use ($toCheckin) {
|
function ($key) use ($toCheckin) {
|
||||||
return $key <= $toCheckin;
|
return $key <= $toCheckin;
|
||||||
},
|
},
|
||||||
ARRAY_FILTER_USE_KEY
|
ARRAY_FILTER_USE_KEY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'tracker',
|
'tracker',
|
||||||
[
|
[
|
||||||
'trip' => $tripData,
|
'trip' => $tripData,
|
||||||
'showAllCheckins' => ($viewMode === 'all'),
|
'showAllCheckins' => ($viewMode === 'all'),
|
||||||
'fromCheckin' => $fromCheckin,
|
'fromCheckin' => $fromCheckin,
|
||||||
'toCheckin' => $toCheckin
|
'toCheckin' => $toCheckin
|
||||||
|
@ -80,8 +84,8 @@ class TrackerController extends Controller
|
||||||
* 1. If the trip is inactive (i.e., finished), use the cache
|
* 1. If the trip is inactive (i.e., finished), use the cache
|
||||||
* 2. If the trip is active:
|
* 2. If the trip is active:
|
||||||
* 1. If the trip was actively tracking at last check, use the
|
* 1. If the trip was actively tracking at last check, use the
|
||||||
* cache if it's less than an hour old. Otherwise, download
|
* cache if it's less than an hour old. Otherwise, download
|
||||||
* the new trip data.
|
* the new trip data.
|
||||||
* 2. If the trip was not actively tracking at lest check, use
|
* 2. If the trip was not actively tracking at lest check, use
|
||||||
* the cache if it's less than three hours old. Otherwise,
|
* the cache if it's less than three hours old. Otherwise,
|
||||||
* download the new trip data.
|
* download the new trip data.
|
||||||
|
@ -91,7 +95,8 @@ class TrackerController extends Controller
|
||||||
* @param bool $forceDownload
|
* @param bool $forceDownload
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_trip_data(string $tripId, bool $forceDownload = false) {
|
public function get_trip_data(string $tripId, bool $forceDownload = false)
|
||||||
|
{
|
||||||
$tripFileName = ( $tripId ?? config('app.current_trip_id') ) . '.json';
|
$tripFileName = ( $tripId ?? config('app.current_trip_id') ) . '.json';
|
||||||
|
|
||||||
// Returns the cached trip data if the trip is inactive (i.e., finished)
|
// Returns the cached trip data if the trip is inactive (i.e., finished)
|
||||||
|
@ -110,11 +115,21 @@ class TrackerController extends Controller
|
||||||
$cachedDataAge = intval(($now->getTimestamp() - $cachedDataUpdatedAt->getTimestamp()) / 3600);
|
$cachedDataAge = intval(($now->getTimestamp() - $cachedDataUpdatedAt->getTimestamp()) / 3600);
|
||||||
|
|
||||||
if ($cachedDataAge <= $cachingTimeout) {
|
if ($cachedDataAge <= $cachingTimeout) {
|
||||||
Log::debug("Cached trip file '{$tripFileName}' is younger than {$cachingTimeout} hours, showing from cache...");
|
Log::debug(
|
||||||
|
"Cached trip file '" .
|
||||||
|
$tripFileName .
|
||||||
|
"' is younger than " .
|
||||||
|
$cachingTimeout .
|
||||||
|
" hours, showing from cache..."
|
||||||
|
);
|
||||||
return $cachedData;
|
return $cachedData;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log::debug("Cached trip file '{$tripFileName}' is for an old trip, showing from cache...");
|
Log::debug(
|
||||||
|
"Cached trip file '" .
|
||||||
|
$tripFileName .
|
||||||
|
"' is for an old trip, showing from cache..."
|
||||||
|
);
|
||||||
return $cachedData;
|
return $cachedData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,29 +148,37 @@ class TrackerController extends Controller
|
||||||
$response = $client->get('trip/'.($tripId ?? config('app.current_trip_id')).'/user/zmld8ko6qy7d9j3xvq10/json');
|
$response = $client->get('trip/'.($tripId ?? config('app.current_trip_id')).'/user/zmld8ko6qy7d9j3xvq10/json');
|
||||||
|
|
||||||
switch ($response->getStatusCode()) {
|
switch ($response->getStatusCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = json_decode($response->getBody());
|
$data = json_decode($response->getBody());
|
||||||
|
|
||||||
// Cache the downloaded file if it does not exist locally.
|
// Cache the downloaded file if it does not exist locally.
|
||||||
if (Storage::disk('local')->missing($tripFileName)) {
|
if (Storage::disk('local')->missing($tripFileName)) {
|
||||||
Log::debug("Caching new trip file '{$tripFileName}'.");
|
Log::debug("Caching new trip file '{$tripFileName}'.");
|
||||||
Storage::disk('local')->put($tripFileName, json_encode($data));
|
|
||||||
} else {
|
|
||||||
$cachedData = json_decode(Storage::disk('local')->get($tripFileName));
|
|
||||||
if ($data->trip->updated_at !== $cachedData->trip->updated_at) {
|
|
||||||
Log::debug("Cached trip file '{$tripFileName}' has different 'updated_at' time, updating cache...");
|
|
||||||
Storage::disk('local')->put($tripFileName, json_encode($data));
|
Storage::disk('local')->put($tripFileName, json_encode($data));
|
||||||
// TODO: Cache photos locally
|
|
||||||
} else {
|
} else {
|
||||||
Log::debug("Cached trip file '{$tripFileName}' has same 'updated_at' time, showing from cache...");
|
$cachedData = json_decode(Storage::disk('local')->get($tripFileName));
|
||||||
$data = $cachedData;
|
if ($data->trip->updated_at !== $cachedData->trip->updated_at) {
|
||||||
|
Log::debug(
|
||||||
|
"Cached trip file '" .
|
||||||
|
$tripFileName .
|
||||||
|
"' has different 'updated_at' time, updating cache..."
|
||||||
|
);
|
||||||
|
Storage::disk('local')->put($tripFileName, json_encode($data));
|
||||||
|
// TODO: Cache photos locally
|
||||||
|
} else {
|
||||||
|
Log::debug(
|
||||||
|
"Cached trip file '" .
|
||||||
|
$tripFileName .
|
||||||
|
"' has same 'updated_at' time, showing from cache..."
|
||||||
|
);
|
||||||
|
$data = $cachedData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $data->trip;
|
return $data->trip;
|
||||||
default:
|
default:
|
||||||
// TODO: Add proper error handling.
|
// TODO: Add proper error handling.
|
||||||
return "Something went wrong";
|
return "Something went wrong";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,32 +49,32 @@ class Digest extends Mailable
|
||||||
|
|
||||||
$cutoffDateTime = new DateTime();
|
$cutoffDateTime = new DateTime();
|
||||||
switch ($this->digest_type) {
|
switch ($this->digest_type) {
|
||||||
case 'daily':
|
case 'daily':
|
||||||
$cutoffDateTime->modify('-1 day');
|
$cutoffDateTime->modify('-1 day');
|
||||||
break;
|
break;
|
||||||
case 'weekly':
|
case 'weekly':
|
||||||
$cutoffDateTime->modify('-1 week');
|
$cutoffDateTime->modify('-1 week');
|
||||||
break;
|
break;
|
||||||
case 'fortnightly':
|
case 'fortnightly':
|
||||||
$cutoffDateTime->modify('-2 weeks');
|
$cutoffDateTime->modify('-2 weeks');
|
||||||
break;
|
break;
|
||||||
case 'monthly':
|
case 'monthly':
|
||||||
$cutoffDateTime->modify('-1 month');
|
$cutoffDateTime->modify('-1 month');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->locations = array_filter(
|
$this->locations = array_filter(
|
||||||
$trip->locations,
|
$trip->locations,
|
||||||
function($elem) use ($cutoffDateTime) {
|
function ($elem) use ($cutoffDateTime) {
|
||||||
$elemDateTime = new DateTime($elem->created_at);
|
$elemDateTime = new DateTime($elem->created_at);
|
||||||
return $elemDateTime > $cutoffDateTime;
|
return $elemDateTime > $cutoffDateTime;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->checkinsList = array_filter(
|
$this->checkinsList = array_filter(
|
||||||
$trip->checkinsList,
|
$trip->checkinsList,
|
||||||
function($elem) use ($cutoffDateTime) {
|
function ($elem) use ($cutoffDateTime) {
|
||||||
$elemDateTime = new DateTime($elem->created_at);
|
$elemDateTime = new DateTime($elem->created_at);
|
||||||
return $elemDateTime > $cutoffDateTime;
|
return $elemDateTime > $cutoffDateTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
if (!function_exists('render_date_difference')) {
|
if (!function_exists('render_date_difference')) {
|
||||||
function render_date_difference ($start_time) {
|
function render_date_difference($start_time)
|
||||||
|
{
|
||||||
$minute = 60;
|
$minute = 60;
|
||||||
$hour = $minute * 60;
|
$hour = $minute * 60;
|
||||||
$day = $hour * 24;
|
$day = $hour * 24;
|
||||||
|
@ -19,19 +20,19 @@ if (!function_exists('render_date_difference')) {
|
||||||
|
|
||||||
if ($trip_start_difference < $minute) {
|
if ($trip_start_difference < $minute) {
|
||||||
$unit = 'second';
|
$unit = 'second';
|
||||||
} else if ($trip_start_difference < $hour) {
|
} elseif ($trip_start_difference < $hour) {
|
||||||
$div = $minute;
|
$div = $minute;
|
||||||
$unit = 'minute';
|
$unit = 'minute';
|
||||||
} else if ($trip_start_difference < $day) {
|
} elseif ($trip_start_difference < $day) {
|
||||||
$div = $hour;
|
$div = $hour;
|
||||||
$unit = 'hour';
|
$unit = 'hour';
|
||||||
} else if ($trip_start_difference < $week) {
|
} elseif ($trip_start_difference < $week) {
|
||||||
$div = $day;
|
$div = $day;
|
||||||
$unit = 'day';
|
$unit = 'day';
|
||||||
} else if ($trip_start_difference < $month) {
|
} elseif ($trip_start_difference < $month) {
|
||||||
$div = $week;
|
$div = $week;
|
||||||
$unit = 'week';
|
$unit = 'week';
|
||||||
} else if ($trip_start_difference < $year) {
|
} elseif ($trip_start_difference < $year) {
|
||||||
$div = $month;
|
$div = $month;
|
||||||
$unit = 'month';
|
$unit = 'month';
|
||||||
} else {
|
} else {
|
||||||
|
@ -39,6 +40,14 @@ if (!function_exists('render_date_difference')) {
|
||||||
$unit = 'year';
|
$unit = 'year';
|
||||||
}
|
}
|
||||||
|
|
||||||
return "{$start_tag}" . ( floor ( $trip_start_difference / $div ) ) . " {$unit}" . ( ( floor ( $trip_start_difference / $div ) > 1 ) ? 's' : '' ) . " ago{$end_tag}";
|
return $start_tag .
|
||||||
|
( floor($trip_start_difference / $div) ) .
|
||||||
|
" {$unit}" .
|
||||||
|
(
|
||||||
|
( floor($trip_start_difference / $div) > 1 ) ?
|
||||||
|
's' :
|
||||||
|
''
|
||||||
|
) .
|
||||||
|
" ago{$end_tag}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
"mockery/mockery": "^1.4.4",
|
"mockery/mockery": "^1.4.4",
|
||||||
"nunomaduro/collision": "^6.1",
|
"nunomaduro/collision": "^6.1",
|
||||||
"phpunit/phpunit": "^9.5.10",
|
"phpunit/phpunit": "^9.5.10",
|
||||||
"spatie/laravel-ignition": "^1.0"
|
"spatie/laravel-ignition": "^1.0",
|
||||||
|
"squizlabs/php_codesniffer": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
60
composer.lock
generated
60
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "44109efc12ef74a29f8aa0c4886fb3d2",
|
"content-hash": "b695d8f60fd5d1e54c8956dd9f120320",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
|
@ -8239,6 +8239,62 @@
|
||||||
],
|
],
|
||||||
"time": "2022-10-26T17:39:54+00:00"
|
"time": "2022-10-26T17:39:54+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "squizlabs/php_codesniffer",
|
||||||
|
"version": "3.7.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
|
||||||
|
"reference": "1359e176e9307e906dc3d890bcc9603ff6d90619"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619",
|
||||||
|
"reference": "1359e176e9307e906dc3d890bcc9603ff6d90619",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-simplexml": "*",
|
||||||
|
"ext-tokenizer": "*",
|
||||||
|
"ext-xmlwriter": "*",
|
||||||
|
"php": ">=5.4.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
|
||||||
|
},
|
||||||
|
"bin": [
|
||||||
|
"bin/phpcs",
|
||||||
|
"bin/phpcbf"
|
||||||
|
],
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"BSD-3-Clause"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Greg Sherwood",
|
||||||
|
"role": "lead"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
|
||||||
|
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
|
||||||
|
"keywords": [
|
||||||
|
"phpcs",
|
||||||
|
"standards"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
|
||||||
|
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
|
||||||
|
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
|
||||||
|
},
|
||||||
|
"time": "2022-06-18T07:21:10+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "theseer/tokenizer",
|
"name": "theseer/tokenizer",
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
|
@ -8299,5 +8355,5 @@
|
||||||
"php": "^8.0.2"
|
"php": "^8.0.2"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.3.0"
|
"plugin-api-version": "2.2.0"
|
||||||
}
|
}
|
||||||
|
|
25
phpcs.xml
Normal file
25
phpcs.xml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset name="PHP_CodeSniffer">
|
||||||
|
<description>The coding standard for our project.</description>
|
||||||
|
<rule ref="PSR2">
|
||||||
|
<exclude name="PSR1.Methods.CamelCapsMethodName"/>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<file>app</file>
|
||||||
|
<file>bootstrap</file>
|
||||||
|
<file>config</file>
|
||||||
|
<file>database</file>
|
||||||
|
<file>resources</file>
|
||||||
|
<file>routes</file>
|
||||||
|
<file>tests</file>
|
||||||
|
|
||||||
|
<exclude-pattern>bootstrap/cache/*</exclude-pattern>
|
||||||
|
<exclude-pattern>bootstrap/autoload.php</exclude-pattern>
|
||||||
|
<exclude-pattern>*/migrations/*</exclude-pattern>
|
||||||
|
<exclude-pattern>*/seeds/*</exclude-pattern>
|
||||||
|
<exclude-pattern>*.blade.php</exclude-pattern>
|
||||||
|
<exclude-pattern>*.js</exclude-pattern>
|
||||||
|
|
||||||
|
<!-- Show progression -->
|
||||||
|
<arg value="p"/>
|
||||||
|
</ruleset>
|
Loading…
Reference in a new issue