Skip to content

Commit

Permalink
Misc: CS fixes & Scrutinizer-ci fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
satrun77 committed Apr 27, 2015
1 parent 3725ebe commit ad3f1c7
Show file tree
Hide file tree
Showing 33 changed files with 866 additions and 457 deletions.
11 changes: 0 additions & 11 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,4 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
protected function schedule(Schedule $schedule)
{
}
}
2 changes: 1 addition & 1 deletion app/Extensions/Html/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function actions(FormInterface $form)
$buttons = $form->actions();
if (!empty($buttons)) {
$actions = Former::actions()->addClass('form-actions');
foreach ($buttons as $name => $options) {
foreach ($buttons as $options) {
if (is_array($options)) {
$actions->{$options['type']}($options['label'], $options);
} else {
Expand Down
172 changes: 4 additions & 168 deletions app/Extensions/Html/HtmlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,122 +20,17 @@
*/
class HtmlBuilder extends \Illuminate\Html\HtmlBuilder
{
/**
* Render tab header from an array
*
* @param array $tabs
* @param string $active
* @param string|null $areaFor
*
* @return string
*/
public function tab(array $tabs, $active, $areaFor = null)
{
$output = '<ul class="nav nav-tabs">';
foreach ($tabs as $tab) {
$output .= '<li role="presentation" ' . ($active == $tab['page'] ? 'class="active"' : '') . '>';

$title = '';
if (isset($tab['count'])) {
$title .= $tab['count'] === 1 ? 1 : (int) $tab['count'];
$title .= ' ';
}
$title .= trans('tinyissue.' . $tab['page']);
$title .= $areaFor == 'project' ? trans('tinyissue.project') : '';

$output .= $this->link($tab['url'], $title);
}
$output .= '</ul>';

return $output;
}

/**
* Render the open tags for box (e.g. blue box)
*
* @param string $style
* @param string|null $title
* @param array $attrs
*
* @return string
*/
public function startBox($style = 'blue-box', $title = null, array $attrs = [])
{
$attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' . $style : $style;
$output = '<div ' . $this->attributes($attrs) . '><div class="inside-pad">';

if (!empty($title)) {
if (is_array($title)) {
$title = '<a href="' . $title[1] . '">' . $title[0] . '</a>';
}
$output .= '<h4>' . $title . '</h4>';
}

$output .= '<div class="content">';

return $output;
}

/**
* Render the closing tags for the box (e.g. blue box)
*
* @param string|null $moreLink
* @param string|null $moreTitle
*
* @return string
*/
public function endBox($moreLink = null, $moreTitle = null)
{
$output = '</div>';

if (!empty($moreLink)) {
$moreTitle = empty($moreTitle) ? $moreTitle : $moreTitle;
$output .= '<a href="' . $moreLink . '" class="view">' . $moreTitle . '</a>';
}

$output .= '</div></div>';

return $output;
}

/**
* Short cut method to call startBox() & endBox()
*
* @param string $content
* @param string $style
* @param string|null $title
* @param string|null $moreLink
* @param string|null $moreTitle
*
* @return string
*/
public function box($content, $style = 'blue-box', $title = null, $moreLink = null, $moreTitle = null)
{
return $this->startBox($style, $title) . $content . $this->endBox($moreLink, $moreTitle);
}

/**
* Format a date
*
* @param int|string $date
* @param string $format
*
* @return string
*/
public function date($date, $format = 'F jS \a\t g:i A')
{
$dateObject = new \DateTime($date);

return $dateObject->format($format);
}
use Traits\BlueBoxTrait,
Traits\TabTrait,
Traits\DateTimeTrait;

/**
* Limit the number of characters in a string, & remove <p> tag
*
* @param string $content
* @param int $size
*
* @return mixed
* @return string
*/
public function trim($content, $size = 60)
{
Expand Down Expand Up @@ -168,65 +63,6 @@ public function filterIssueNo($content)
return preg_replace('/((?:' . trans('tinyissue.issue') . ')?)(\s*)#(\d+)/i', $link, $content);
}

/**
* Displays the timestamp's age in human readable format
*
* @param int $timestamp
*
* @return string
*/
public function age($timestamp)
{
if (!$timestamp instanceof \DateTime) {
$timestamp = new \DateTime($timestamp);
}

$timestamp = $timestamp->getTimestamp();
$difference = time() - $timestamp;
$periods = ['second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade'];
$lengths = ['60', '60', '24', '7', '4.35', '12', '10'];
for ($j = 0; $difference >= $lengths[$j]; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if ($difference != 1) {
$periods[$j] .= 's';
}

return $difference . ' ' . $periods[$j] . ' ago';
}

/**
* Convert seconds into time duration format
*
* @param int $seconds
*
* @return string
*/
public function duration($seconds)
{
$hours = floor($seconds / 3600);
$minutes = ($seconds / 60) % 60;
$seconds = $seconds % 60;

$output = '';
$separatorChar = ', ';
$separator = '';
if ($hours > 0) {
$output .= $hours . ' ' . trans('tinyissue.short_hours');
$separator = $separatorChar;
}
if ($minutes > 0) {
$output .= $separator . $minutes . ' ' . trans('tinyissue.short_minutes');
$separator = $separatorChar;
}
if ($seconds > 0) {
$output .= $separator . $seconds . ' ' . trans('tinyissue.short_seconds');
}

return $output;
}

/**
* Render loading Html
*
Expand Down
88 changes: 88 additions & 0 deletions app/Extensions/Html/Traits/BlueBoxTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/*
* This file is part of the Tinyissue package.
*
* (c) Mohamed Alsharaf <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Tinyissue\Extensions\Html\Traits;

use Illuminate\Html\HtmlBuilder;

/**
* BlueBoxTrait is trait class for adding methods to generate the html code of the blue box
*
* @author Mohamed Alsharaf <[email protected]>
*
* @method HtmlBuilder attributes($relations)
*/
trait BlueBoxTrait
{
/**
* Short cut method to call startBox() & endBox()
*
* @param string $content
* @param string $style
* @param string|null $title
* @param string|null $moreLink
* @param string|null $moreTitle
*
* @return string
*/
public function box($content, $style = 'blue-box', $title = null, $moreLink = null, $moreTitle = null)
{
return $this->startBox($style, $title) . $content . $this->endBox($moreLink, $moreTitle);
}

/**
* Render the open tags for box (e.g. blue box)
*
* @param string $style
* @param string|null $title
* @param array $attrs
*
* @return string
*/
public function startBox($style = 'blue-box', $title = null, array $attrs = [])
{
$attrs['class'] = isset($attrs['class']) ? $attrs['class'] . ' ' . $style : $style;
$output = '<div ' . $this->attributes($attrs) . '><div class="inside-pad">';

if (!empty($title)) {
if (is_array($title)) {
$title = '<a href="' . $title[1] . '">' . $title[0] . '</a>';
}
$output .= '<h4>' . $title . '</h4>';
}

$output .= '<div class="content">';

return $output;
}

/**
* Render the closing tags for the box (e.g. blue box)
*
* @param string|null $moreLink
* @param string|null $moreTitle
*
* @return string
*/
public function endBox($moreLink = null, $moreTitle = null)
{
$output = '</div>';

if (!empty($moreLink)) {
$moreTitle = empty($moreTitle) ? $moreTitle : $moreTitle;
$output .= '<a href="' . $moreLink . '" class="view">' . $moreTitle . '</a>';
}

$output .= '</div></div>';

return $output;
}
}
Loading

0 comments on commit ad3f1c7

Please sign in to comment.