Passed
Push — master ( 275bab...ff10b0 )
by Maxence
03:14
created

PicoService::getAbsolutePathFromPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
/**
3
 * CMS Pico - Integration of Pico within your files to create websites.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\CMSPico\Service;
28
29
use OC\App\AppManager;
0 ignored issues
show
Bug introduced by
The type OC\App\AppManager 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...
30
use OCA\CMSPico\AppInfo\Application;
31
use OCA\CMSPico\Model\Website;
32
use Pico;
33
34
class PicoService {
35
36
	const DIR_CONFIG = 'Pico/config/';
37
	const DIR_PLUGINS = 'Pico/plugins/';
38
	const DIR_THEMES = 'Pico/themes/';
39
40
	private $userId;
41
42
	/** @var AppManager */
43
	private $appManager;
44
45
	/** @var MiscService */
46
	private $miscService;
47
48
	/**
49
	 * PicoService constructor.
50
	 *
51
	 * @param string $userId
52
	 * @param AppManager $appManager
53
	 * @param MiscService $miscService
54
	 */
55
	function __construct($userId, AppManager $appManager, MiscService $miscService) {
56
		$this->userId = $userId;
57
		$this->appManager = $appManager;
58
		$this->miscService = $miscService;
59
	}
60
61
62
	/**
63
	 * @param Website $website
64
	 *
65
	 * @return string
66
	 */
67
	public function getContent(Website $website) {
68
69
		$appPath = MiscService::endSlash($this->appManager->getAppPath(Application::APP_NAME));
0 ignored issues
show
Bug introduced by
$this->appManager->getAp...\Application::APP_NAME) cannot be passed to OCA\CMSPico\Service\MiscService::endSlash() as the parameter $path expects a reference. ( Ignorable by Annotation )

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

69
		$appPath = MiscService::endSlash(/** @scrutinizer ignore-type */ $this->appManager->getAppPath(Application::APP_NAME));
Loading history...
70
		$pico = new Pico(
71
			$website->getAbsolutePath(), self::DIR_CONFIG,
72
			$appPath . self::DIR_PLUGINS,
73
			$appPath . self::DIR_THEMES
74
		);
75
76
		$this->generateConfig($pico, $website);
77
		$content = $pico->run();
78
79
		$absolutePath = $this->getAbsolutePathFromPage($pico);
80
		$website->contentMustBeLocal($absolutePath);
81
		$website->viewerMustHaveAccess($absolutePath, $pico->getFileMeta());
82
83
		return $content;
84
	}
85
86
87
	/**
88
	 * @param Pico $pico
89
	 * @param Website $website
90
	 */
91
	private function generateConfig(Pico &$pico, Website $website) {
92
		$pico->setConfig(
93
			[
94
				'content_dir' => 'content/',
95
				'content_ext' => '.md',
96
				'theme'       => $website->getTheme(),
97
				'site_title'  => $website->getName(),
98
				'base_url'    => \OC::$WEBROOT . $website->getSite()
99
			]
100
		);
101
	}
102
103
104
	/**
105
	 * @param Pico $pico
106
	 *
107
	 * @return string
108
	 */
109
	private function getAbsolutePathFromPage(Pico $pico) {
110
		return $pico->getConfig()['content_dir'] . $pico->getCurrentPage()['id'] . ' . md';
111
	}
112
113
}