FileStorageUI::fileLabel()   B
last analyzed

Complexity

Conditions 11
Paths 48

Size

Total Lines 42
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 27
c 1
b 0
f 0
nc 48
nop 6
dl 0
loc 42
rs 7.3166

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Epesi\FileStorage;
4
5
use Epesi\FileStorage\Models\File;
6
use Epesi\Core\Helpers\Utils;
7
8
class FileStorageUI
9
{
10
	
11
	public static function fileLabel($id, $nolink = false, $icon = true, $action_urls = null, $label = null, $inline = false)
12
	{
13
		$fileExists = File::exists($id);
14
		
15
		if ($icon) {
16
			$icon_file = $fileExists ? 'z-attach.png': 'z-attach-off.png';
17
			$img_src = Base_ThemeCommon::get_template_file(self::module_name(), $icon_file);
0 ignored issues
show
Bug introduced by
The method module_name() does not exist on Epesi\FileStorage\FileStorageUI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
			$img_src = Base_ThemeCommon::get_template_file(self::/** @scrutinizer ignore-call */ module_name(), $icon_file);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The type Epesi\FileStorage\Base_ThemeCommon was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
			$icon_img = '<img src="' . $img_src . '" style="vertical-align:bottom">';
19
		}
20
		else {
21
			$icon_img = '';
22
		}
23
		
24
		$file = File::get($id);
0 ignored issues
show
Bug Best Practice introduced by
The method atk4\data\Model::get() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
		/** @scrutinizer ignore-call */ 
25
  $file = File::get($id);
Loading history...
25
				
26
		if (! $fileName = $label) {
27
			$fileName = ($file['name']?? '') ?: '[' . __('missing file name') . ']';
0 ignored issues
show
Bug introduced by
Are you sure __('missing file name') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
			$fileName = ($file['name']?? '') ?: '[' . /** @scrutinizer ignore-type */ __('missing file name') . ']';
Loading history...
28
		}
29
		
30
		if ($nolink || ! $file) {
31
			return $fileName . ($fileExists ? '': ' [' . __('missing file') . ']');
0 ignored issues
show
Bug introduced by
Are you sure __('missing file') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
			return $fileName . ($fileExists ? '': ' [' . /** @scrutinizer ignore-type */ __('missing file') . ']');
Loading history...
32
		}
33
		
34
		$link_href = '';
35
		if ($fileExists) {
36
			$filesize = filesize_hr($file['file']);
0 ignored issues
show
Bug introduced by
The function filesize_hr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
			$filesize = /** @scrutinizer ignore-call */ filesize_hr($file['file']);
Loading history...
37
			$filetooltip = __('File size: %s', array($filesize)) . '<hr>' .
0 ignored issues
show
Bug introduced by
Are you sure __('File size: %s', array($filesize)) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
			$filetooltip = /** @scrutinizer ignore-type */ __('File size: %s', array($filesize)) . '<hr>' .
Loading history...
38
					__('Uploaded by: %s', array(Base_UserCommon::get_user_label($file['created_by'], true))) . '<br/>' .
0 ignored issues
show
Bug introduced by
The type Epesi\FileStorage\Base_UserCommon was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
Are you sure __('Uploaded by: %s', ar...['created_by'], true))) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
					/** @scrutinizer ignore-type */ __('Uploaded by: %s', array(Base_UserCommon::get_user_label($file['created_by'], true))) . '<br/>' .
Loading history...
39
					__('Uploaded on: %s', array(Base_RegionalSettingsCommon::time2reg($file['created_on']))) . '<br/>' .
0 ignored issues
show
Bug introduced by
The type Epesi\FileStorage\Base_RegionalSettingsCommon was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
Are you sure __('Uploaded on: %s', ar...($file['created_on']))) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
					/** @scrutinizer ignore-type */ __('Uploaded on: %s', array(Base_RegionalSettingsCommon::time2reg($file['created_on']))) . '<br/>' .
Loading history...
40
					__('Number of downloads: %d', array(self::get_downloads_count($id)));
0 ignored issues
show
Bug introduced by
Are you sure __('Number of downloads:..._downloads_count($id))) of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
					/** @scrutinizer ignore-type */ __('Number of downloads: %d', array(self::get_downloads_count($id)));
Loading history...
Bug introduced by
The method get_downloads_count() does not exist on Epesi\FileStorage\FileStorageUI. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
					__('Number of downloads: %d', array(self::/** @scrutinizer ignore-call */ get_downloads_count($id)));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
					$link_href = Utils_TooltipCommon::open_tag_attrs($filetooltip) . ' '
0 ignored issues
show
Bug introduced by
The type Epesi\FileStorage\Utils_TooltipCommon was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
							. Utils_FileStorage_FileLeightbox::get_file_leightbox($file, $action_urls);
0 ignored issues
show
Bug introduced by
The type Epesi\FileStorage\Utils_FileStorage_FileLeightbox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
		} else {
44
			if (isset($file['hash'])) {
45
				$tooltip_text = __('Missing file: %s', array(substr($file['hash'], 0, 32) . '...'));
46
				$link_href = Utils_TooltipCommon::open_tag_attrs($tooltip_text);
47
			}
48
		}
49
		
50
		$ret = '<a ' . $link_href . '>' . $icon_img . '<span class="file_name">' . $fileName . '</span></a>';
51
		
52
		return $inline? $ret: '<div class="file_link">'.$ret.'</div>';
53
	}
54
}
55