Skip to content

Commit

Permalink
Restart linting effort. Partial progress on phpcs feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovett committed Dec 14, 2018
1 parent c22d0ff commit 727e322
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 51 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -6,6 +6,7 @@ fakeseed: dummy

lint: dummy
phpmd app text phpmd.xml
phpcs -s app

# Install NPM packages quietly.
#setup-js: export NPM_CONFIG_PROGRESS = false
Expand Down
6 changes: 4 additions & 2 deletions app/Client.php
Expand Up @@ -60,7 +60,7 @@ class Client extends Model
*/
protected $casts = [
'active' => 'boolean',
'totalTime' => 'integer'
'totalTime' => 'integer',
];

/**
Expand Down Expand Up @@ -114,6 +114,9 @@ function ($join) {
return $builder;
}

/**
* At-a-glance numbers that summarize a client in various ways.
*/
public function stats()
{
$stats = [];
Expand Down Expand Up @@ -183,5 +186,4 @@ public function estimates()
{
return $this->hasMany('App\Estimate');
}

}
14 changes: 8 additions & 6 deletions app/Console/Kernel.php
Expand Up @@ -5,28 +5,29 @@
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

/**
* Standard Laravel Console Kernel
*/
class Kernel extends ConsoleKernel
{

/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
protected $commands = [];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @param Schedule $schedule A schedule instance.
*
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command(null);
// $schedule->command('inspire')
// ->hourly();
}

/**
Expand All @@ -38,6 +39,7 @@ protected function commands()
{
$this->load(__DIR__.'/Commands');

// phpcs:disable PEAR
require base_path('routes/console.php');
}
}
10 changes: 5 additions & 5 deletions app/Helpers/CurrencyHelper.php
Expand Up @@ -7,28 +7,28 @@
class CurrencyHelper
{


/**
* Format a monetary value with cents
*
* @param float $value The value to format.
*
* @return string
*/
public static function money($value)
public static function money(float $value)
{
return money_format('%.2n', $value);
}

/**
* Calculate an hourly rate
*
* @param float $money Total money
* @param int $minutes Total time
* @param float $money Total money.
* @param int $minutes Total time.
*
* @return int Hourly money, rounded
*
*/
public static function hourlyRate($money=0, $minutes=0)
public static function hourlyRate(float $money = 0, int $minutes = 0)
{
if ($minutes < 1) {
return '';
Expand Down
58 changes: 38 additions & 20 deletions app/Helpers/LinkHelper.php
Expand Up @@ -10,21 +10,23 @@
*/
class LinkHelper
{


/**
* Render a primary navigation link with awareness of the current route
*
* If the route matches resource of the current route, the link is
* displayed in the active state.
*
* @param string $section The current section declared by the controller
* @param string $route The route to link to
* @param string $label The text of the link
* @param array $params Querystring parameters to include with the link
* @param array $attribs Additional attributes for the link tag
*
* @return string
*/
public static function primaryNavLink($route, $label, array $params = [], array $attribs = []) {
public static function primaryNavLink(string $route, string $label, array $params = [], array $attribs = [])
{
$resource = static::firstRouteSegment();
$linkedRoute = explode('.', $route);
$liClass = 'nav-item';
Expand All @@ -46,7 +48,15 @@ public static function primaryNavLink($route, $label, array $params = [], array
);
}

public static function buttonLink($route, $label, array $params = [], array $attribs = [])
/**
* Render a link as a button.
*
* @param string $route The route to link to
* @param string $label The text of the link
* @param array $params Querystring parameters to include with the link
* @param array $attribs Additional attributes for the link tag
*/
public static function buttonLink(string $route, string $label, array $params = [], array $attribs = [])
{
$class = 'btn btn-primary';

Expand All @@ -58,16 +68,19 @@ public static function buttonLink($route, $label, array $params = [], array $att
return link_to_route($route, $label, $params, $attribs);
}

public static function smallButtonLink($route, $label, array $params = [], array $attributes = [])
{
$attributes['class'] = 'btn-sm';
return static::buttonLink($route, $label, $params, $attributes);
}

public static function extraSmallButtonLink($route, $label, array $params = [], array $attributes = [])
/**
* Render a link as a small button.
*
* @param string $route The route to link to
* @param string $label The text of the link
* @param array $params Querystring parameters to include with the link
* @param array $attribs Additional attributes for the link tag
*/
public static function smallButtonLink(string $route, string $label, array $params = [], array $attribs = [])
{
$attributes['class'] = 'btn-xs';
return static::buttonLink($route, $label, $params, $attributes);
$attribs['class'] = 'btn-sm';
return static::buttonLink($route, $label, $params, $attribs);
}

/**
Expand All @@ -76,15 +89,15 @@ public static function extraSmallButtonLink($route, $label, array $params = [],
* If the route matches the current route, the link is displayed
* in the active state.
*
* @param string $section The current section declared by the controller
* @param string $route The route to link to
* @param string $label The text of the link
* @param array $params Querystring parameters to include with the link
* @param array $attribs Additional attributes for the link tag
*
* @return string
*/
public static function navLink($route, $label, array $params = [], array $attribs = []) {
public static function navLink(string $route, string $label, array $params = [], array $attribs = [])
{
$liClass = 'nav-item';
$linkClass = 'nav-link';

Expand Down Expand Up @@ -113,10 +126,11 @@ public static function navLink($route, $label, array $params = [], array $attrib
*
* @return boolean
*/
public static function showSubnav() {
public static function showSubnav()
{
$routeSegments = explode('.', Route::currentRouteName());

return sizeof($routeSegments) > 1;
return count($routeSegments) > 1;
}

/**
Expand All @@ -127,7 +141,8 @@ public static function showSubnav() {
*
* @return array
*/
public static function getSubnav() {
public static function getSubnav()
{
$action = Route::getCurrentRoute()->getActionName();
$params = Route::getCurrentRoute()->parameters;

Expand All @@ -140,18 +155,21 @@ public static function getSubnav() {
return $links;
}

$links[] = LinkHelper::navLink("{$resource}.index", "{$capitalizedResource} List", []);
$links[] = self::navLink("{$resource}.index", "{$capitalizedResource} List", []);

if (strpos($action, '@show') !== false || strpos($action, '@edit') !== false) {
$links[] = LinkHelper::navLink("{$resource}.show", "{$capitalizedResource} Overview", $params);
$links[] = LinkHelper::navLink("{$resource}.edit", "Edit {$capitalizedResource}", $params);
$links[] = self::navLink("{$resource}.show", "{$capitalizedResource} Overview", $params);
$links[] = self::navLink("{$resource}.edit", "Edit {$capitalizedResource}", $params);
}

$links[] = LinkHelper::navLink("{$resource}.create", "New {$capitalizedResource}", []);
$links[] = self::navLink("{$resource}.create", "New {$capitalizedResource}", []);

return $links;
}

/**
* Return the first segment of the current route.
*/
public static function firstRouteSegment()
{
$routeSegments = explode('.', Route::currentRouteName());
Expand Down
31 changes: 25 additions & 6 deletions app/Helpers/MessagingHelper.php
Expand Up @@ -10,27 +10,46 @@
*
* The value of the userMessageType key should be one of:
* success, info, warning, danger.
*
* @see https://getbootstrap.com/docs/3.3/components/#alerts
*/
class MessagingHelper
{
public static function flashCreated($label='') {


/**
* Flash a standard message to the session about record creation.
*
* @param string $label The name of the newly-created record type.
*/
public static function flashCreated(string $label = '')
{
$resource = ucfirst(LinkHelper::firstRouteSegment());
Session::flash('userMessage', "{$resource} {$label} has been created.");
Session::flash('userMessageType', 'success');
}

public static function flashUpdated($label='') {

/**
* Flash a standard message to the session about a record being successfully updated.
*
* @param string $label The name of the newly-updated record type.
*/
public static function flashUpdated(string $label = '')
{
$resource = ucfirst(LinkHelper::firstRouteSegment());
Session::flash('userMessage', "{$resource} {$label} has been updated.");
Session::flash('userMessageType', 'success');
}

public static function flashDeleted($label='') {

/**
* Flash a standard message to the session about a record being successfully deleted.
*
* @param string $label The name of the newly-updated record type.
*/
public static function flashDeleted(string $label = '')
{
$resource = ucfirst(LinkHelper::firstRouteSegment());
Session::flash('userMessage', "{$resource} {$label} has been deleted.");
Session::flash('userMessageType', 'success');
}

}

0 comments on commit 727e322

Please sign in to comment.