Skip to content

Commit

Permalink
Fix php-cs-fixer errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lehecht committed Feb 6, 2024
1 parent 727baf7 commit e0b1f8a
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions app/Http/Requests/StoreVideoAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function withValidator($validator)

if ($this->input('shape_id') !== Shape::wholeFrameId()) {

$containsNonArray = collect($this->input('points'))->filter(fn($p) => gettype($p) !== 'array')->isNotEmpty();
$containsNonArray = collect($this->input('points'))->filter(fn ($p) => gettype($p) !== 'array')->isNotEmpty();
if ($containsNonArray) {
$validator->errors()->add('points', 'Invalid shape. Either has no points or points in wrong format.');
return;
Expand All @@ -113,35 +113,36 @@ public function withValidator($validator)
$exactValue = true;

switch ($this->input('shape_id')) {
case(Shape::circleId()):
case (Shape::circleId()):
$shapes = collect($this->input('points'));
if ($shapes->filter(fn($xyr) => count($xyr) !== 3)->isNotEmpty() || $shapes->filter(fn($xyr) => $xyr[2] === 0)->isNotEmpty()) {
if ($shapes->filter(fn ($xyr) => count($xyr) !== 3)->isNotEmpty() || $shapes->filter(fn ($xyr) => $xyr[2] === 0)->isNotEmpty()) {
$validator->errors()->add('points', 'Invalid shape.');
}
return;
case(Shape::ellipseId()):
case(Shape::rectangleId()):
case (Shape::ellipseId()):
case (Shape::rectangleId()):
$expectedElementCount = 8;
$exactValue = true;
break;
case(Shape::lineId()):
case (Shape::lineId()):
$expectedElementCount = 4;
$exactValue = false;
break;
case(Shape::polygonId()):
case (Shape::polygonId()):
$expectedElementCount = 6;
$exactValue = false;
break;
case (Shape::pointId()):
$expectedElementCount = 2;
$exactValue = true;

}
if ($this->hasInvalidShapes($shapes, $expectedElementCount, $exactValue)) {
$validator->errors()->add('points', 'Invalid shape.');
}
}


});
}

Expand Down Expand Up @@ -181,11 +182,11 @@ protected function annotationContained()

/**
* Checks if shapes have invalid number of (distinct) points
*
*
* @param array $pointArrays containing coordinates of (multiple) shapes
* @param int $expectedCount number of expected x and y coordinates
* @param bool $exact is used in check for exact or minimum count
*
*
* @return bool false is shape is valid, otherwise true
* **/
private function hasInvalidShapes($pointArrays, $expectedCount, $exact)
Expand All @@ -196,9 +197,9 @@ private function hasInvalidShapes($pointArrays, $expectedCount, $exact)
return true;
}

$x = $pointCollection->filter(fn($x, $idx) => $idx % 2 === 0)->values();
$y = $pointCollection->filter(fn($x, $idx) => $idx % 2 === 1)->values();
$coords = collect($x->map(fn($x, $idx) => [$x, $y[$idx]]))->unique();
$x = $pointCollection->filter(fn ($x, $idx) => $idx % 2 === 0)->values();
$y = $pointCollection->filter(fn ($x, $idx) => $idx % 2 === 1)->values();
$coords = collect($x->map(fn ($x, $idx) => [$x, $y[$idx]]))->unique();

if ($exact && (count($coords) !== $expectedCount / 2) || !$exact && ((count($coords) < $expectedCount / 2))) {
return true;
Expand Down

0 comments on commit e0b1f8a

Please sign in to comment.