File MediaUploadHandler.php
has 559 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* @link http://www.writesdown.com/
* @copyright Copyright (c) 2015 WritesDown
* @license http://www.writesdown.com/license/
MediaUploadHandler
has 34 functions (exceeds 20 allowed). Consider refactoring. Open
class MediaUploadHandler
{
const PRINT_RESPONSE = true;
const NOT_PRINT_RESPONSE = false;
Method createScaledImage
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function createScaledImage($fileName, $version, $options)
{
$success = false;
$filePath = $this->getFilePath($fileName);
$image = Image::getImagine()->open($filePath);
Function createScaledImage
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
protected function createScaledImage($fileName, $version, $options)
{
$success = false;
$filePath = $this->getFilePath($fileName);
$image = Image::getImagine()->open($filePath);
- 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 setOptions
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function setOptions($options = [])
{
$this->options = [
'script_url' => Yii::$app->request->absoluteUrl,
'upload_dir' => Yii::getAlias('@public/uploads/'),
Function post
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function post($printResponse = self::PRINT_RESPONSE)
{
if (Yii::$app->request->get('delete') && $id = Yii::$app->request->get('id')) {
return $this->delete($id, $printResponse);
}
- 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 post
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function post($printResponse = self::PRINT_RESPONSE)
{
if (Yii::$app->request->get('delete') && $id = Yii::$app->request->get('id')) {
return $this->delete($id, $printResponse);
}
Function correctExifRotation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
protected function correctExifRotation($image, $filePath)
{
if (!function_exists('exif_read_data')) {
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
Function get
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function get($id = null, $printResponse = self::PRINT_RESPONSE)
{
$content = [];
if ($id && $media = $this->findMedia($id)) {
- 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 setIconUrl
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function setIconUrl($fileName)
{
foreach ($this->fileTypes as $name => $type) {
if (preg_match($type['extensions'], $fileName)) {
if ($name === '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 generateResponse
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function generateResponse($media)
{
$metadata = $media->getMeta('metadata');
$response = ArrayHelper::merge(ArrayHelper::toArray($media), $metadata);
$response['date_formatted'] = Yii::$app->formatter->asDatetime($media->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"