Passed
Push — developer ( c475b4...5772fb )
by Mariusz
69:56 queued 34:42
created

LibraryMoreInfo::getModalIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Library more info view file.
5
 *
6
 * @package View
7
 *
8
 * @copyright YetiForce Sp. z o.o
9
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
10
 * @author    Arkadiusz Sołek <[email protected]>
11
 */
12
13
namespace YF\Modules\YetiForce\View;
14
15
/**
16
 * Library more info view class.
17
 */
18
class LibraryMoreInfo extends \App\Controller\Modal
19
{
20
	/** @var array Public libraries package files. */
21
	public $packageFiles = ['package.json', 'composer.json', 'bower.json'];
22
23
	/** {@inheritdoc} */
24
	public function checkPermission(): void
25
	{
26
	}
27
28
	/**  {@inheritdoc}  */
29
	public function getTitle(): string
30
	{
31
		return \App\Language::translate('LBL_MORE_LIBRARY_INFO', $this->moduleName);
32
	}
33
34
	/**  {@inheritdoc}  */
35
	public function getModalIcon(): string
36
	{
37
		return 'fas fa-info-circle';
38
	}
39
40
	/** {@inheritdoc} */
41
	public function validateRequest(): void
42
	{
43
		$this->request->validateWriteAccess();
44
	}
45
46
	/** {@inheritdoc} */
47
	public function process(): void
48
	{
49
		$result = false;
50
		$fileContent = '';
51
		if ($this->request->isEmpty('type') || $this->request->isEmpty('libraryName')) {
52
			$result = false;
53
		} else {
54
			if ('public' === $this->request->get('type')) {
55
				$dir = ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'public_html' . \DIRECTORY_SEPARATOR . 'libraries' . \DIRECTORY_SEPARATOR;
56
				$libraryName = $this->request->get('libraryName');
57
				foreach ($this->packageFiles as $file) {
58
					$packageFile = $dir . $libraryName . \DIRECTORY_SEPARATOR . $file;
59
					if ($fileContent) {
60
						continue;
61
					}
62 View Code Duplication
					if (file_exists($packageFile)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
						$fileContent = file_get_contents($packageFile);
64
						$result = true;
65
					} else {
66
						$result = false;
67
					}
68
				}
69
			} elseif ('vendor' === $this->request->get('type')) {
70
				$filePath = 'vendor' . \DIRECTORY_SEPARATOR . $this->request->get('libraryName') . \DIRECTORY_SEPARATOR . 'composer.json';
71
72 View Code Duplication
				if (file_exists($filePath)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
					$fileContent = file_get_contents($filePath);
74
					$result = true;
75
				} else {
76
					$result = false;
77
				}
78
			} else {
79
				$result = false;
80
			}
81
		}
82
		$moduleName = $this->request->getModule(false);
0 ignored issues
show
Unused Code introduced by
The call to Request::getModule() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
83
		$this->viewer->assign('QUALIFIED_MODULE', $moduleName);
84
		$this->viewer->assign('RESULT', $result);
85
		$this->viewer->assign('FILE_CONTENT', $fileContent);
86
		$this->viewer->view('LibraryMoreInfo.tpl', $moduleName);
87
	}
88
}
89