Passed
Push — master ( 3c5c4c...9b7e24 )
by Morris
10:49 queued 12s
created
core/Controller/SvgController.php 2 patches
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -43,104 +43,104 @@
 block discarded – undo
43 43
 
44 44
 class SvgController extends Controller {
45 45
 
46
-	/** @var string */
47
-	protected $serverRoot;
48
-
49
-	/** @var ITimeFactory */
50
-	protected $timeFactory;
51
-
52
-	/** @var IAppManager */
53
-	protected $appManager;
54
-
55
-	/** @var IconsCacher */
56
-	private $iconsCacher;
57
-
58
-	public function __construct(string $appName,
59
-								IRequest $request,
60
-								ITimeFactory $timeFactory,
61
-								IAppManager $appManager,
62
-								IconsCacher $iconsCacher) {
63
-		parent::__construct($appName, $request);
64
-
65
-		$this->serverRoot  = \OC::$SERVERROOT;
66
-		$this->timeFactory = $timeFactory;
67
-		$this->appManager = $appManager;
68
-		$this->iconsCacher = $iconsCacher;
69
-	}
70
-
71
-	/**
72
-	 * @PublicPage
73
-	 * @NoCSRFRequired
74
-	 * @NoSameSiteCookieRequired
75
-	 *
76
-	 * Generate svg from filename with the requested color
77
-	 *
78
-	 * @param string $folder
79
-	 * @param string $fileName
80
-	 * @param string $color
81
-	 * @return DataDisplayResponse|NotFoundResponse
82
-	 */
83
-	public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') {
84
-		$path = $this->serverRoot . "/core/img/$folder/$fileName.svg";
85
-		return $this->getSvg($path, $color, $fileName);
86
-	}
87
-
88
-	/**
89
-	 * @PublicPage
90
-	 * @NoCSRFRequired
91
-	 * @NoSameSiteCookieRequired
92
-	 *
93
-	 * Generate svg from filename with the requested color
94
-	 *
95
-	 * @param string $app
96
-	 * @param string $fileName
97
-	 * @param string $color
98
-	 * @return DataDisplayResponse|NotFoundResponse
99
-	 */
100
-	public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') {
101
-		try {
102
-			$appPath = $this->appManager->getAppPath($app);
103
-		} catch (AppPathNotFoundException $e) {
104
-			return new NotFoundResponse();
105
-		}
106
-
107
-		$path = $appPath . "/img/$fileName.svg";
108
-		return $this->getSvg($path, $color, $fileName);
109
-	}
110
-
111
-	/**
112
-	 * Generate svg from filename with the requested color
113
-	 *
114
-	 * @param string $path
115
-	 * @param string $color
116
-	 * @param string $fileName
117
-	 * @return DataDisplayResponse|NotFoundResponse
118
-	 */
119
-	private function getSvg(string $path, string $color, string $fileName) {
120
-		if (!file_exists($path)) {
121
-			return new NotFoundResponse();
122
-		}
123
-
124
-		$svg = file_get_contents($path);
125
-
126
-		if ($svg === null) {
127
-			return new NotFoundResponse();
128
-		}
129
-
130
-		$svg = $this->iconsCacher->colorizeSvg($svg, $color);
131
-
132
-		$response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
133
-
134
-		// Set cache control
135
-		$ttl = 31536000;
136
-		$response->cacheFor($ttl);
137
-		$response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"');
138
-		$expires = new \DateTime();
139
-		$expires->setTimestamp($this->timeFactory->getTime());
140
-		$expires->add(new \DateInterval('PT' . $ttl . 'S'));
141
-		$response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
142
-		$response->addHeader('Pragma', 'cache');
143
-
144
-		return $response;
145
-	}
46
+    /** @var string */
47
+    protected $serverRoot;
48
+
49
+    /** @var ITimeFactory */
50
+    protected $timeFactory;
51
+
52
+    /** @var IAppManager */
53
+    protected $appManager;
54
+
55
+    /** @var IconsCacher */
56
+    private $iconsCacher;
57
+
58
+    public function __construct(string $appName,
59
+                                IRequest $request,
60
+                                ITimeFactory $timeFactory,
61
+                                IAppManager $appManager,
62
+                                IconsCacher $iconsCacher) {
63
+        parent::__construct($appName, $request);
64
+
65
+        $this->serverRoot  = \OC::$SERVERROOT;
66
+        $this->timeFactory = $timeFactory;
67
+        $this->appManager = $appManager;
68
+        $this->iconsCacher = $iconsCacher;
69
+    }
70
+
71
+    /**
72
+     * @PublicPage
73
+     * @NoCSRFRequired
74
+     * @NoSameSiteCookieRequired
75
+     *
76
+     * Generate svg from filename with the requested color
77
+     *
78
+     * @param string $folder
79
+     * @param string $fileName
80
+     * @param string $color
81
+     * @return DataDisplayResponse|NotFoundResponse
82
+     */
83
+    public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') {
84
+        $path = $this->serverRoot . "/core/img/$folder/$fileName.svg";
85
+        return $this->getSvg($path, $color, $fileName);
86
+    }
87
+
88
+    /**
89
+     * @PublicPage
90
+     * @NoCSRFRequired
91
+     * @NoSameSiteCookieRequired
92
+     *
93
+     * Generate svg from filename with the requested color
94
+     *
95
+     * @param string $app
96
+     * @param string $fileName
97
+     * @param string $color
98
+     * @return DataDisplayResponse|NotFoundResponse
99
+     */
100
+    public function getSvgFromApp(string $app, string $fileName, string $color = 'ffffff') {
101
+        try {
102
+            $appPath = $this->appManager->getAppPath($app);
103
+        } catch (AppPathNotFoundException $e) {
104
+            return new NotFoundResponse();
105
+        }
106
+
107
+        $path = $appPath . "/img/$fileName.svg";
108
+        return $this->getSvg($path, $color, $fileName);
109
+    }
110
+
111
+    /**
112
+     * Generate svg from filename with the requested color
113
+     *
114
+     * @param string $path
115
+     * @param string $color
116
+     * @param string $fileName
117
+     * @return DataDisplayResponse|NotFoundResponse
118
+     */
119
+    private function getSvg(string $path, string $color, string $fileName) {
120
+        if (!file_exists($path)) {
121
+            return new NotFoundResponse();
122
+        }
123
+
124
+        $svg = file_get_contents($path);
125
+
126
+        if ($svg === null) {
127
+            return new NotFoundResponse();
128
+        }
129
+
130
+        $svg = $this->iconsCacher->colorizeSvg($svg, $color);
131
+
132
+        $response = new DataDisplayResponse($svg, Http::STATUS_OK, ['Content-Type' => 'image/svg+xml']);
133
+
134
+        // Set cache control
135
+        $ttl = 31536000;
136
+        $response->cacheFor($ttl);
137
+        $response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"');
138
+        $expires = new \DateTime();
139
+        $expires->setTimestamp($this->timeFactory->getTime());
140
+        $expires->add(new \DateInterval('PT' . $ttl . 'S'));
141
+        $response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
142
+        $response->addHeader('Pragma', 'cache');
143
+
144
+        return $response;
145
+    }
146 146
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 * @return DataDisplayResponse|NotFoundResponse
82 82
 	 */
83 83
 	public function getSvgFromCore(string $folder, string $fileName, string $color = 'ffffff') {
84
-		$path = $this->serverRoot . "/core/img/$folder/$fileName.svg";
84
+		$path = $this->serverRoot."/core/img/$folder/$fileName.svg";
85 85
 		return $this->getSvg($path, $color, $fileName);
86 86
 	}
87 87
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 			return new NotFoundResponse();
105 105
 		}
106 106
 
107
-		$path = $appPath . "/img/$fileName.svg";
107
+		$path = $appPath."/img/$fileName.svg";
108 108
 		return $this->getSvg($path, $color, $fileName);
109 109
 	}
110 110
 
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 		// Set cache control
135 135
 		$ttl = 31536000;
136 136
 		$response->cacheFor($ttl);
137
-		$response->addHeader('Content-Disposition', 'inline; filename="' . $fileName . '.svg"');
137
+		$response->addHeader('Content-Disposition', 'inline; filename="'.$fileName.'.svg"');
138 138
 		$expires = new \DateTime();
139 139
 		$expires->setTimestamp($this->timeFactory->getTime());
140
-		$expires->add(new \DateInterval('PT' . $ttl . 'S'));
140
+		$expires->add(new \DateInterval('PT'.$ttl.'S'));
141 141
 		$response->addHeader('Expires', $expires->format(\DateTime::RFC1123));
142 142
 		$response->addHeader('Pragma', 'cache');
143 143
 
Please login to merge, or discard this patch.