File Preview.php
has 665 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @author Björn Schießle <bjoern@schiessle.org>
* @author Frank Karlitschek <frank@karlitschek.de>
* @author Georg Ehrke <georg@owncloud.com>
Preview
has 45 functions (exceeds 20 allowed). Consider refactoring. Open
class Preview {
//the thumbnail folder
public const THUMBNAILS_FOLDER = 'thumbnails';
public const MODE_FILL = 'fill';
Function generatePreview
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private function generatePreview() {
$file = $this->getFile();
$preview = null;
$previewProviders = \OC::$server->getPreviewManager()
- 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 getPreview
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function getPreview() {
if ($this->preview !== null && $this->preview->valid()) {
return $this->preview;
}
- 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 resizeAndStore
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function resizeAndStore() {
$image = $this->preview;
if (!($image instanceof IImage)) {
Util::writeLog(
'core',
Function deletePreview
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function deletePreview($keepMax = true) {
$fileInfo = $this->getFile();
if ($fileInfo !== null && $fileInfo !== false) {
if ($keepMax === true) {
$previewPath = $this->buildCachePath();
- 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 generatePreview
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function generatePreview() {
$file = $this->getFile();
$preview = null;
$previewProviders = \OC::$server->getPreviewManager()
Method getPreview
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getPreview() {
if ($this->preview !== null && $this->preview->valid()) {
return $this->preview;
}
Function isCached
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function isCached() {
$fileId = $this->getFile()->getId();
if ($fileId === null) {
return false;
}
- 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 cropAndFill
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function cropAndFill($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
if ($previewWidth > $askedWidth) {
$cropX = \floor(($previewWidth - $askedWidth) * 0.5);
$image->crop($cropX, 0, $askedWidth, $previewHeight);
$previewWidth = $askedWidth;
Method scale
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function scale($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
$scalingUp = $this->getScalingUp();
$maxScaleFactor = $this->getMaxScaleFactor();
$factorX = $askedWidth / $previewWidth;
Method isCached
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function isCached() {
$fileId = $this->getFile()->getId();
if ($fileId === null) {
return false;
}
Method __construct
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
$user = '',
$root = '/',
Node $file = null,
$maxX = 1,
$maxY = 1,
Function unscalable
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function unscalable($x, $y) {
$maxX = $this->getMaxX();
$maxY = $this->getMaxY();
$scalingUp = $this->getScalingUp();
$maxScaleFactor = $this->getMaxScaleFactor();
- 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 resizeAndStore
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function resizeAndStore() {
$image = $this->preview;
if (!($image instanceof IImage)) {
Util::writeLog(
'core',
- 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 scale
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function scale($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
$scalingUp = $this->getScalingUp();
$maxScaleFactor = $this->getMaxScaleFactor();
$factorX = $askedWidth / $previewWidth;
- 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 crop
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function crop($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight = null) {
Method cropAndFill
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function cropAndFill($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
Method scale
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function scale($image, $askedWidth, $askedHeight, $previewWidth, $previewHeight) {
Function getCachedPreview
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function getCachedPreview($cached) {
$stream = $this->userView->fopen($cached, 'r');
$this->preview = null;
if ($stream) {
$image = new \OC_Image();
- 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 getPossibleThumbnails
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function getPossibleThumbnails($allThumbnails) {
if ($this->keepAspect) {
$wantedAspectRatio = (float)($this->maxPreviewWidth / $this->maxPreviewHeight);
} else {
$wantedAspectRatio = (float)($this->getMaxX() / $this->getMaxY());
- 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 false;
Avoid too many return
statements within this method. Open
return $this->isCachedBigger($allThumbnails);
Function showPreview
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function showPreview($mimeTypeForHeaders = null) {
// Check if file is valid
if ($this->isFileValid() === false) {
throw new NotFoundException('File not found.');
}
- 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 buildCachePath
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function buildCachePath($maxX = null, $maxY = null) {
if ($maxX === null) {
$maxX = $this->getMaxX();
}
if ($maxY === null) {
- 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"