Code clean up.

This commit is contained in:
James Cole
2017-11-15 12:25:49 +01:00
parent 57dcdfa0c4
commit ffca858b8d
476 changed files with 2055 additions and 4181 deletions

View File

@@ -18,7 +18,6 @@
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support;
@@ -27,19 +26,17 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
/**
* Class Navigation
*
* @package FireflyIII\Support
* Class Navigation.
*/
class Navigation
{
/**
* @param \Carbon\Carbon $theDate
* @param $repeatFreq
* @param $skip
*
* @return \Carbon\Carbon
*
* @throws FireflyException
*/
public function addPeriod(Carbon $theDate, string $repeatFreq, int $skip): Carbon
@@ -75,7 +72,7 @@ class Navigation
// if period is 1M and diff in month is 2 and new DOM = 1, sub a day:
$months = ['1M', 'month', 'monthly'];
$difference = $date->month - $theDate->month;
if (in_array($repeatFreq, $months) && $difference === 2 && $date->day === 1) {
if (in_array($repeatFreq, $months) && 2 === $difference && 1 === $date->day) {
$date->subDay();
}
@@ -87,6 +84,7 @@ class Navigation
* @param $repeatFreq
*
* @return \Carbon\Carbon
*
* @throws FireflyException
*/
public function endOfPeriod(\Carbon\Carbon $end, string $repeatFreq): Carbon
@@ -113,7 +111,7 @@ class Navigation
// if the range is custom, the end of the period
// is another X days (x is the difference between start)
// and end added to $theCurrentEnd
if ($repeatFreq === 'custom') {
if ('custom' === $repeatFreq) {
/** @var Carbon $tStart */
$tStart = session('start', Carbon::now()->startOfMonth());
/** @var Carbon $tEnd */
@@ -178,7 +176,7 @@ class Navigation
$currentEnd->$function();
}
if (!is_null($maxDate) && $currentEnd > $maxDate) {
if (null !== $maxDate && $currentEnd > $maxDate) {
return clone $maxDate;
}
@@ -227,6 +225,7 @@ class Navigation
* @param $repeatFrequency
*
* @return string
*
* @throws FireflyException
*/
public function periodShow(Carbon $theDate, string $repeatFrequency): string
@@ -248,13 +247,12 @@ class Navigation
'year' => trans('config.year'),
'yearly' => trans('config.year'),
'6M' => trans('config.half_year'),
];
if (isset($formatMap[$repeatFrequency])) {
return $date->formatLocalized(strval($formatMap[$repeatFrequency]));
}
if ($repeatFrequency === '3M' || $repeatFrequency === 'quarter') {
if ('3M' === $repeatFrequency || 'quarter' === $repeatFrequency) {
$quarter = ceil($theDate->month / 3);
return sprintf('Q%d %d', $quarter, $theDate->year);
@@ -384,6 +382,7 @@ class Navigation
* @param $repeatFreq
*
* @return \Carbon\Carbon
*
* @throws FireflyException
*/
public function startOfPeriod(Carbon $theDate, string $repeatFreq): Carbon
@@ -412,7 +411,7 @@ class Navigation
return $date;
}
if ($repeatFreq === 'half-year' || $repeatFreq === '6M') {
if ('half-year' === $repeatFreq || '6M' === $repeatFreq) {
$month = $date->month;
$date->startOfYear();
if ($month >= 7) {
@@ -421,11 +420,10 @@ class Navigation
return $date;
}
if ($repeatFreq === 'custom') {
if ('custom' === $repeatFreq) {
return $date; // the date is already at the start.
}
throw new FireflyException(sprintf('Cannot do startOfPeriod for $repeat_freq "%s"', $repeatFreq));
}
@@ -435,6 +433,7 @@ class Navigation
* @param int $subtract
*
* @return \Carbon\Carbon
*
* @throws FireflyException
*/
public function subtractPeriod(Carbon $theDate, string $repeatFreq, int $subtract = 1): Carbon
@@ -476,7 +475,7 @@ class Navigation
// a custom range requires the session start
// and session end to calculate the difference in days.
// this is then subtracted from $theDate (* $subtract).
if ($repeatFreq === 'custom') {
if ('custom' === $repeatFreq) {
/** @var Carbon $tStart */
$tStart = session('start', Carbon::now()->startOfMonth());
/** @var Carbon $tEnd */
@@ -495,6 +494,7 @@ class Navigation
* @param \Carbon\Carbon $start
*
* @return \Carbon\Carbon
*
* @throws FireflyException
*/
public function updateEndDate(string $range, Carbon $start): Carbon
@@ -515,7 +515,7 @@ class Navigation
return $end;
}
if ($range === '6M') {
if ('6M' === $range) {
if ($start->month >= 7) {
$end->endOfYear();
@@ -533,6 +533,7 @@ class Navigation
* @param \Carbon\Carbon $start
*
* @return \Carbon\Carbon
*
* @throws FireflyException
*/
public function updateStartDate(string $range, Carbon $start): Carbon
@@ -551,7 +552,7 @@ class Navigation
return $start;
}
if ($range === '6M') {
if ('6M' === $range) {
if ($start->month >= 7) {
$start->startOfYear()->addMonths(6);