Skip to content

Commit b5d82a6

Browse files
committed
Fixes for PSR-12 code style
1 parent f7628b8 commit b5d82a6

File tree

3 files changed

+59
-37
lines changed

3 files changed

+59
-37
lines changed

src/PhpRenderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
namespace Slim\Views;
1313

14-
use \InvalidArgumentException;
14+
use InvalidArgumentException;
1515
use Psr\Http\Message\ResponseInterface;
1616

1717
/**
@@ -183,10 +183,10 @@ public function fetchTemplate(string $template, array $data = []): string
183183
ob_start();
184184
$this->protectedIncludeScope($this->templatePath . $template, $data);
185185
$output = ob_get_clean();
186-
} catch(\Throwable $e) { // PHP 7+
186+
} catch (\Throwable $e) { // PHP 7+
187187
ob_end_clean();
188188
throw $e;
189-
} catch(\Exception $e) { // PHP < 7
189+
} catch (\Exception $e) { // PHP < 7
190190
ob_end_clean();
191191
throw $e;
192192
}
@@ -197,7 +197,7 @@ public function fetchTemplate(string $template, array $data = []): string
197197
/**
198198
* Include template within a separate scope for extracted $data
199199
*/
200-
protected function protectedIncludeScope (string $template, array $data): void
200+
protected function protectedIncludeScope(string $template, array $data): void
201201
{
202202
extract($data);
203203
include func_get_arg(0);

tests/PhpRendererTest.php

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
declare(strict_types=1);
44

5+
namespace Slim\ViewsTest;
6+
57
use PHPUnit\Framework\TestCase;
68
use Slim\Psr7\Headers;
79
use Slim\Psr7\Response;
810
use Slim\Psr7\Stream;
11+
use Slim\Views\PhpRenderer;
12+
use Throwable;
913

1014
/**
1115
* Created by PhpStorm.
@@ -16,37 +20,40 @@
1620
class PhpRendererTest extends TestCase
1721
{
1822

19-
public function testRenderer() {
20-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/");
23+
public function testRenderer()
24+
{
25+
$renderer = new PhpRenderer(__DIR__ . "/_files/");
2126

2227
$headers = new Headers();
2328
$body = new Stream(fopen('php://temp', 'r+'));
2429
$response = new Response(200, $headers, $body);
2530

26-
$newResponse = $renderer->render($response, "template.phtml", array("hello" => "Hi"));
31+
$newResponse = $renderer->render($response, "template.phtml", ["hello" => "Hi"]);
2732

2833
$newResponse->getBody()->rewind();
2934

3035
$this->assertEquals("Hi", $newResponse->getBody()->getContents());
3136
}
3237

33-
public function testRenderConstructor() {
34-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files");
38+
public function testRenderConstructor()
39+
{
40+
$renderer = new PhpRenderer(__DIR__ . "/_files");
3541

3642
$headers = new Headers();
3743
$body = new Stream(fopen('php://temp', 'r+'));
3844
$response = new Response(200, $headers, $body);
3945

40-
$newResponse = $renderer->render($response, "template.phtml", array("hello" => "Hi"));
46+
$newResponse = $renderer->render($response, "template.phtml", ["hello" => "Hi"]);
4147

4248
$newResponse->getBody()->rewind();
4349

4450
$this->assertEquals("Hi", $newResponse->getBody()->getContents());
4551
}
4652

47-
public function testAttributeMerging() {
53+
public function testAttributeMerging()
54+
{
4855

49-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/", [
56+
$renderer = new PhpRenderer(__DIR__ . "/_files/", [
5057
"hello" => "Hello"
5158
]);
5259

@@ -61,15 +68,16 @@ public function testAttributeMerging() {
6168
$this->assertEquals("Hi", $newResponse->getBody()->getContents());
6269
}
6370

64-
public function testExceptionInTemplate() {
65-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/");
71+
public function testExceptionInTemplate()
72+
{
73+
$renderer = new PhpRenderer(__DIR__ . "/_files/");
6674

6775
$headers = new Headers();
6876
$body = new Stream(fopen('php://temp', 'r+'));
6977
$response = new Response(200, $headers, $body);
7078

7179
try {
72-
$newResponse = $renderer->render($response, "testException.php");
80+
$newResponse = $renderer->render($response, "exception_layout.phtml");
7381
} catch (Throwable $t) { // PHP 7+
7482
// Simulates an error template
7583
$newResponse = $renderer->render($response, "template.phtml", [
@@ -90,9 +98,9 @@ public function testExceptionInTemplate() {
9098
/**
9199
* @expectedException InvalidArgumentException
92100
*/
93-
public function testExceptionForTemplateInData() {
94-
95-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/");
101+
public function testExceptionForTemplateInData()
102+
{
103+
$renderer = new PhpRenderer(__DIR__ . "/_files/");
96104

97105
$headers = new Headers();
98106
$body = new Stream(fopen('php://temp', 'r+'));
@@ -106,9 +114,10 @@ public function testExceptionForTemplateInData() {
106114
/**
107115
* @expectedException RuntimeException
108116
*/
109-
public function testTemplateNotFound() {
117+
public function testTemplateNotFound()
118+
{
110119

111-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/");
120+
$renderer = new PhpRenderer(__DIR__ . "/_files/");
112121

113122
$headers = new Headers();
114123
$body = new Stream(fopen('php://temp', 'r+'));
@@ -117,37 +126,42 @@ public function testTemplateNotFound() {
117126
$renderer->render($response, "adfadftemplate.phtml", []);
118127
}
119128

120-
public function testLayout() {
121-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/", ["title" => "My App"]);
129+
public function testLayout()
130+
{
131+
$renderer = new PhpRenderer(__DIR__ . "/_files/", ["title" => "My App"]);
122132
$renderer->setLayout("layout.phtml");
123133

124134
$headers = new Headers();
125135
$body = new Stream(fopen('php://temp', 'r+'));
126136
$response = new Response(200, $headers, $body);
127137

128-
$newResponse = $renderer->render($response, "template.phtml", array("title" => "Hello - My App", "hello" => "Hi"));
138+
$newResponse = $renderer->render($response, "template.phtml", ["title" => "Hello - My App", "hello" => "Hi"]);
129139

130140
$newResponse->getBody()->rewind();
131141

132-
$this->assertEquals("<html><head><title>Hello - My App</title></head><body>Hi<footer>This is the footer</footer></body></html>", $newResponse->getBody()->getContents());
142+
$this->assertEquals("<html><head><title>Hello - My App</title></head><body>Hi<footer>This is the footer"
143+
. "</footer></body></html>", $newResponse->getBody()->getContents());
133144
}
134145

135-
public function testLayoutConstructor() {
136-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files", ["title" => "My App"], "layout.phtml");
146+
public function testLayoutConstructor()
147+
{
148+
$renderer = new PhpRenderer(__DIR__ . "/_files", ["title" => "My App"], "layout.phtml");
137149

138150
$headers = new Headers();
139151
$body = new Stream(fopen('php://temp', 'r+'));
140152
$response = new Response(200, $headers, $body);
141153

142-
$newResponse = $renderer->render($response, "template.phtml", array("title" => "Hello - My App", "hello" => "Hi"));
154+
$newResponse = $renderer->render($response, "template.phtml", ["title" => "Hello - My App", "hello" => "Hi"]);
143155

144156
$newResponse->getBody()->rewind();
145157

146-
$this->assertEquals("<html><head><title>Hello - My App</title></head><body>Hi<footer>This is the footer</footer></body></html>", $newResponse->getBody()->getContents());
158+
$this->assertEquals("<html><head><title>Hello - My App</title></head><body>Hi<footer>This is the footer"
159+
. "</footer></body></html>", $newResponse->getBody()->getContents());
147160
}
148161

149-
public function testExceptionInLayout() {
150-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/");
162+
public function testExceptionInLayout()
163+
{
164+
$renderer = new PhpRenderer(__DIR__ . "/_files/");
151165
$renderer->setLayout("exception_layout.phtml");
152166

153167
$headers = new Headers();
@@ -178,9 +192,10 @@ public function testExceptionInLayout() {
178192
/**
179193
* @expectedException RuntimeException
180194
*/
181-
public function testLayoutNotFound() {
195+
public function testLayoutNotFound()
196+
{
182197

183-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/");
198+
$renderer = new PhpRenderer(__DIR__ . "/_files/");
184199
$renderer->setLayout("non-existent_layout.phtml");
185200

186201
$headers = new Headers();
@@ -190,18 +205,24 @@ public function testLayoutNotFound() {
190205
$renderer->render($response, "template.phtml", []);
191206
}
192207

193-
public function testContentDataKeyShouldBeIgnored() {
194-
$renderer = new \Slim\Views\PhpRenderer(__DIR__ . "/_files/");
208+
public function testContentDataKeyShouldBeIgnored()
209+
{
210+
$renderer = new PhpRenderer(__DIR__ . "/_files/");
195211
$renderer->setLayout("layout.phtml");
196212

197213
$headers = new Headers();
198214
$body = new Stream(fopen('php://temp', 'r+'));
199215
$response = new Response(200, $headers, $body);
200216

201-
$newResponse = $renderer->render($response, "template.phtml", array("title" => "Hello - My App", "hello" => "Hi", "content" => "Ho"));
217+
$newResponse = $renderer->render(
218+
$response,
219+
"template.phtml",
220+
["title" => "Hello - My App", "hello" => "Hi", "content" => "Ho"]
221+
);
202222

203223
$newResponse->getBody()->rewind();
204224

205-
$this->assertEquals("<html><head><title>Hello - My App</title></head><body>Hi<footer>This is the footer</footer></body></html>", $newResponse->getBody()->getContents());
225+
$this->assertEquals("<html><head><title>Hello - My App</title></head><body>Hi<footer>This is the footer"
226+
. "</footer></body></html>", $newResponse->getBody()->getContents());
206227
}
207228
}

tests/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?php
2+
23
/**
34
* Created by PhpStorm.
45
* User: Glenn
56
* Date: 2015-11-12
67
* Time: 11:31 AM
78
*/
89

9-
include "vendor/autoload.php";
10+
include "vendor/autoload.php";

0 commit comments

Comments
 (0)