summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-01-04 12:05:19 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-01-04 12:05:19 +0000
commit0a20058d3f27dc0d27cf6d0ed602bda6a38248e6 (patch)
treed30eac4659e1ac7d2b28720e85e4cf47587c702a /app
parent16cfb0b94e88dec264e0a7bcd26b5b085d1822ea (diff)
downloadwebtrees-0a20058d3f27dc0d27cf6d0ed602bda6a38248e6.tar.gz
webtrees-0a20058d3f27dc0d27cf6d0ed602bda6a38248e6.tar.bz2
webtrees-0a20058d3f27dc0d27cf6d0ed602bda6a38248e6.zip
Use constant arrays instead of static variables
Diffstat (limited to 'app')
-rw-r--r--app/Http/Controllers/SourceController.php46
1 files changed, 23 insertions, 23 deletions
diff --git a/app/Http/Controllers/SourceController.php b/app/Http/Controllers/SourceController.php
index bf4f213d66..adc7dc6719 100644
--- a/app/Http/Controllers/SourceController.php
+++ b/app/Http/Controllers/SourceController.php
@@ -28,6 +28,24 @@ use Symfony\Component\HttpFoundation\Response;
*/
class SourceController extends AbstractBaseController
{
+ // Show the source's facts in this order:
+ private const FACT_ORDER = [
+ 'TITL' => 0,
+ 'ABBR' => 1,
+ 'AUTH' => 2,
+ 'DATA' => 3,
+ 'PUBL' => 4,
+ 'TEXT' => 5,
+ 'REPO' => 6,
+ 'NOTE' => 7,
+ 'OBJE' => 8,
+ 'REFN' => 9,
+ 'RIN' => 10,
+ '_UID' => 11,
+ 'CHAN' => 12,
+ 'RESN' => 13,
+ ];
+
/**
* Show a repository's page.
*
@@ -64,30 +82,12 @@ class SourceController extends AbstractBaseController
{
$facts = $record->facts();
- usort(
- $facts,
- function (Fact $x, Fact $y): int {
- static $order = [
- 'TITL' => 0,
- 'ABBR' => 1,
- 'AUTH' => 2,
- 'DATA' => 3,
- 'PUBL' => 4,
- 'TEXT' => 5,
- 'NOTE' => 6,
- 'OBJE' => 7,
- 'REFN' => 8,
- 'RIN' => 9,
- '_UID' => 10,
- 'CHAN' => 11,
- ];
+ usort($facts, function (Fact $x, Fact $y): int {
+ $sort_x = self::FACT_ORDER[$x->getTag()] ?? PHP_INT_MAX;
+ $sort_y = self::FACT_ORDER[$y->getTag()] ?? PHP_INT_MAX;
- return
- (array_key_exists($x->getTag(), $order) ? $order[$x->getTag()] : PHP_INT_MAX)
- -
- (array_key_exists($y->getTag(), $order) ? $order[$y->getTag()] : PHP_INT_MAX);
- }
- );
+ return $sort_x <=> $sort_y;
+ });
return $facts;
}