File Fact.php
has 478 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2023 webtrees development team
Fact
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class Fact
{
private const FACT_ORDER = [
'BIRT',
'_HNM',
Function label
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function label(): string
{
if (str_ends_with($this->tag(), ':NOTE') && preg_match('/^@' . Gedcom::REGEX_XREF . '@$/', $this->value())) {
return I18N::translate('Shared note');
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function summary
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function summary(): string
{
$attributes = [];
$target = $this->target();
if ($target instanceof GedcomRecord) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method target
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function target()
{
if (!preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $this->value(), $match)) {
return null;
}
Function typeComparator
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public static function typeComparator(): Closure
{
static $factsort = [];
if ($factsort === []) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method typeComparator
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function typeComparator(): Closure
{
static $factsort = [];
if ($factsort === []) {
Method sortFacts
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function sortFacts(Collection $unsorted): Collection
{
$dated = [];
$nondated = [];
$sorted = [];
Method summary
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function summary(): string
{
$attributes = [];
$target = $this->target();
if ($target instanceof GedcomRecord) {
Function sortFacts
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function sortFacts(Collection $unsorted): Collection
{
$dated = [];
$nondated = [];
$sorted = [];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method canShow
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function canShow(int|null $access_level = null): bool
{
$access_level ??= Auth::accessLevel($this->record->tree());
// Does this record have an explicit restriction notice?
Function name
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function name(): string
{
$items = [$this->label()];
$target = $this->target();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function canShow
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function canShow(int|null $access_level = null): bool
{
$access_level ??= Auth::accessLevel($this->record->tree());
// Does this record have an explicit restriction notice?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function dateComparator
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private static function dateComparator(): Closure
{
return static function (Fact $a, Fact $b): int {
if ($a->date()->isOK() && $b->date()->isOK()) {
// If both events have dates, compare by date
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return Registry::sourceFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return Registry::repositoryFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return Registry::mediaFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return $individual_fact_privacy[$xref][$this->tag] >= $access_level;
Avoid too many return
statements within this method. Open
return Registry::submissionFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return Registry::submitterFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return Registry::locationFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return Registry::noteFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $fact_privacy[$this->tag] >= $access_level;
Avoid too many return
statements within this method. Open
return Registry::gedcomRecordFactory()->make($xref, $this->record->tree());
Avoid too many return
statements within this method. Open
return Registry::elementFactory()->make($this->tag())->label();