From 1d15bc0b10a20110fbdf36ce8230fa0b34a4d3ea Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 3 Nov 2016 21:54:07 +0100 Subject: [PATCH] I am changing some string concatenations to sprintf() routines because they are more readable and safer. [skip ci] --- app/Console/Commands/UpgradeDatabase.php | 2 +- .../Commands/UpgradeFireflyInstructions.php | 5 ++--- app/Support/Navigation.php | 14 +++++++------- app/Support/Preferences.php | 6 +++--- app/Support/Twig/Transaction.php | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php index 5b0ed46a5f..2c1a4dee63 100644 --- a/app/Console/Commands/UpgradeDatabase.php +++ b/app/Console/Commands/UpgradeDatabase.php @@ -99,7 +99,7 @@ class UpgradeDatabase extends Command } catch (QueryException $e) { Log::error($e->getMessage()); $this->error('Firefly III could not find the "identifier" field in the "transactions" table.'); - $this->error('This field is required for Firefly III version ' . config('firefly.version') . ' to run.'); + $this->error(sprintf('This field is required for Firefly III version %s to run.', config('firefly.version'))); $this->error('Please run "php artisan migrate" to add this field to the table.'); $this->info('Then, run "php artisan firefly:upgrade-database" to try again.'); break 2; diff --git a/app/Console/Commands/UpgradeFireflyInstructions.php b/app/Console/Commands/UpgradeFireflyInstructions.php index 234b075f7a..df007ab40f 100644 --- a/app/Console/Commands/UpgradeFireflyInstructions.php +++ b/app/Console/Commands/UpgradeFireflyInstructions.php @@ -64,15 +64,14 @@ class UpgradeFireflyInstructions extends Command } - if (is_null($text)) { - $this->line('Thank you for installing Firefly III, v' . $version); + $this->line(sprintf('Thank you for installing Firefly III, v%s', $version)); $this->info('There are no extra upgrade instructions.'); $this->line('Firefly III should be ready for use.'); } else { $this->line('+------------------------------------------------------------------------------+'); $this->line(''); - $this->line('Thank you for installing Firefly III, v' . $version); + $this->line(sprintf('Thank you for installing Firefly III, v%s', $version)); $this->info(wordwrap($text)); $this->line(''); $this->line('+------------------------------------------------------------------------------+'); diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 4ea2318acb..665873596e 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -54,7 +54,7 @@ class Navigation ]; if (!isset($functionMap[$repeatFreq])) { - throw new FireflyException('Cannot do addPeriod for $repeat_freq "' . $repeatFreq . '"'); + throw new FireflyException(sprintf('Cannot do addPeriod for $repeat_freq "%s"', $repeatFreq)); } if (isset($modifierMap[$repeatFreq])) { $add = $add * $modifierMap[$repeatFreq]; @@ -108,7 +108,7 @@ class Navigation } if (!isset($functionMap[$repeatFreq])) { - throw new FireflyException('Cannot do endOfPeriod for $repeat_freq "' . $repeatFreq . '"'); + throw new FireflyException(sprintf('Cannot do endOfPeriod for $repeat_freq "%s"', $repeatFreq)); } $function = $functionMap[$repeatFreq]; if (isset($modifierMap[$repeatFreq])) { @@ -202,7 +202,7 @@ class Navigation if (isset($formatMap[$repeatFrequency])) { return $date->formatLocalized(strval($formatMap[$repeatFrequency])); } - throw new FireflyException('No date formats for frequency "' . $repeatFrequency . '"!'); + throw new FireflyException(sprintf('No date formats for frequency "%s"!', $repeatFrequency)); } /** @@ -252,7 +252,7 @@ class Navigation } - throw new FireflyException('Cannot do startOfPeriod for $repeat_freq "' . $repeatFreq . '"'); + throw new FireflyException(sprintf('Cannot do startOfPeriod for $repeat_freq "%s"', $repeatFreq)); } /** @@ -313,7 +313,7 @@ class Navigation return $date; } - throw new FireflyException('Cannot do subtractPeriod for $repeat_freq "' . $repeatFreq . '"'); + throw new FireflyException(sprintf('Cannot do subtractPeriod for $repeat_freq "%s"', $repeatFreq)); } /** @@ -350,7 +350,7 @@ class Navigation return $end; } - throw new FireflyException('updateEndDate cannot handle $range "' . $range . '"'); + throw new FireflyException(sprintf('updateEndDate cannot handle range "%s"', $range)); } /** @@ -387,7 +387,7 @@ class Navigation } - throw new FireflyException('updateStartDate cannot handle $range "' . $range . '"'); + throw new FireflyException(sprintf('updateStartDate cannot handle range "%s"', $range)); } diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 8471745dbc..55ed08c6dc 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -32,7 +32,7 @@ class Preferences */ public function delete($name): bool { - $fullName = 'preference' . auth()->user()->id . $name; + $fullName = sprintf('preference%s%s', auth()->user()->id, $name); if (Cache::has($fullName)) { Cache::forget($fullName); } @@ -66,7 +66,7 @@ class Preferences */ public function getForUser(User $user, $name, $default = null) { - $fullName = 'preference' . $user->id . $name; + $fullName = sprintf('preference%s%s', $user->id, $name); if (Cache::has($fullName)) { return Cache::get($fullName); } @@ -138,7 +138,7 @@ class Preferences */ public function setForUser(User $user, $name, $value): Preference { - $fullName = 'preference' . $user->id . $name; + $fullName = sprintf('preference%s%s', $user->id, $name); Cache::forget($fullName); $pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data']); diff --git a/app/Support/Twig/Transaction.php b/app/Support/Twig/Transaction.php index a5b98f34d1..696464932c 100644 --- a/app/Support/Twig/Transaction.php +++ b/app/Support/Twig/Transaction.php @@ -125,7 +125,7 @@ class Transaction extends Twig_Extension && bccomp($amount, bcmul($transactionAmount, '-1')) !== 0 ) { // not equal? - return ' (' . Amount::formatWithCode($code, $amount, true) . ')'; + return sprintf(' (%s)', Amount::formatWithCode($code, $amount, true)); } return '';