Skip to content

Commit a722c96

Browse files
Merge pull request #69 from imanghafoori1/analysis-7a3kJZ
Apply fixes from StyleCI [ci skip] [skip ci]
2 parents a14f492 + c086cd5 commit a722c96

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

src/Utils/SlotRenderer.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,41 @@ trait SlotRenderer
99
protected $slots = [];
1010

1111
/**
12-
* Start output buffer to get content of slot and set slot name
13-
*
14-
* @param String $name
12+
* Start output buffer to get content of slot and set slot name.
13+
*
14+
* @param string $name
1515
*/
1616
public function startSlot($name)
1717
{
18-
if (ob_start())
18+
if (ob_start()) {
1919
$this->slotName = $name;
20+
}
2021
}
2122

2223
/**
23-
* get slot content from widget block
24-
*
25-
* @param String $data
24+
* get slot content from widget block.
25+
*
26+
* @param string $data
2627
*/
27-
public function renderSlot($data = "")
28+
public function renderSlot($data = '')
2829
{
2930
$this->slots[$this->slotName] = $data;
3031
}
3132

3233
/**
33-
* check if widget has any slots
34-
*
35-
* @return Boolean
34+
* check if widget has any slots.
35+
*
36+
* @return bool
3637
*/
3738
public function hasSlots()
3839
{
39-
return !empty($this->slots);
40+
return ! empty($this->slots);
4041
}
4142

4243
/**
43-
* get and clean current slots
44-
*
45-
* @return Array $slots
44+
* get and clean current slots.
45+
*
46+
* @return array $slots
4647
*/
4748
public function getSlots()
4849
{

src/Utils/WidgetRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class WidgetRenderer
88
{
99
use SlotRenderer;
10-
10+
1111
public $html;
1212

1313
private $_viewData;

src/WidgetsServiceProvider.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public function boot()
1919
{
2020
$this->_registerDebugbar();
2121
$this->publishes([
22-
__DIR__ . '/config/config.php' => config_path('widgetize.php'),
22+
__DIR__.'/config/config.php' => config_path('widgetize.php'),
2323
]);
2424

2525
$this->defineDirectives();
26-
$this->loadViewsFrom($this->app->basePath() . '/app/Widgets/', 'Widgets');
26+
$this->loadViewsFrom($this->app->basePath().'/app/Widgets/', 'Widgets');
2727
}
2828

2929
/**
@@ -46,14 +46,15 @@ private function defineDirectives()
4646
return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderWidget{$expression}; ?>";
4747
});
4848

49-
Blade::directive('slotWidget', function ($expression) use ($omitParenthesis) {
49+
Blade::directive('slotWidget', function ($expression) use ($omitParenthesis) {
5050
$this->expression = $omitParenthesis ? $expression : "($expression)";
5151
});
5252

5353
$this->defineSlotDirectives($omitParenthesis);
5454

5555
Blade::directive('endSlotWidget', function () {
5656
$expression = $this->expression;
57+
5758
return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderWidget{$expression}; ?>";
5859
});
5960
}
@@ -72,11 +73,13 @@ private function defineSlotDirectives($omitParenthesis)
7273
{
7374
Blade::directive('slot', function ($slotName) use ($omitParenthesis) {
7475
$slotName = $omitParenthesis ? $slotName : "($slotName)";
76+
7577
return "<?php echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->startSlot{$slotName};?>";
7678
});
7779

7880
Blade::directive('endSlot', function () {
7981
$contentKey = '$content';
82+
8083
return "<?php
8184
$contentKey = ob_get_clean();
8285
echo app(\\Imanghafoori\\Widgets\\Utils\\WidgetRenderer::class)->renderSlot($contentKey);
@@ -91,15 +94,15 @@ private function defineSlotDirectives($omitParenthesis)
9194
*/
9295
public function register()
9396
{
94-
$this->mergeConfigFrom(__DIR__ . '/config/config.php', 'widgetize');
97+
$this->mergeConfigFrom(__DIR__.'/config/config.php', 'widgetize');
9598
$this->commands('command.imanghafoori.widget');
9699
app(RouteMacros::class)->registerMacros();
97100
app(SingletonServices::class)->registerSingletons($this->app);
98101
}
99102

100103
private function _registerDebugbar()
101104
{
102-
if (!$this->app->offsetExists('debugbar')) {
105+
if (! $this->app->offsetExists('debugbar')) {
103106
return;
104107
}
105108

tests/SlotWidgetTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Facades\View;
4-
use \Imanghafoori\Widgets\Utils\WidgetRenderer;
4+
use Imanghafoori\Widgets\Utils\WidgetRenderer;
55

66
require_once 'test_stubs.php';
77

@@ -23,7 +23,7 @@ public function test_set_slot()
2323
$this->assertEquals(false, $renderer->hasSlots());
2424

2525
$renderer->startSlot('message');
26-
$renderer->renderSlot("<h1> test set slot </h1>");
26+
$renderer->renderSlot('<h1> test set slot </h1>');
2727
ob_end_clean();
2828

2929
$this->assertEquals(true, $renderer->hasSlots());
@@ -32,7 +32,7 @@ public function test_set_slot()
3232
public function test_get_then_remove_current_slots()
3333
{
3434
$slotName = 'message';
35-
$slotContent = "<h1> test set and clean slot </h1>";
35+
$slotContent = '<h1> test set and clean slot </h1>';
3636

3737
$renderer = $this->renderer;
3838

@@ -87,24 +87,24 @@ public function test_widget_with_many_slots()
8787

8888
$slots = [
8989
'header_links' => "<a href='#'> login </a>",
90-
'message' => "<h1> this is my message </h1>",
91-
'footer_links' => "<a href='#'> about us </a>"
90+
'message' => '<h1> this is my message </h1>',
91+
'footer_links' => "<a href='#'> about us </a>",
9292
];
9393

9494
View::shouldReceive('exists')->once()->andReturn(true);
9595
View::shouldReceive('make')->once()
9696
->with('hello', ['data' => 'bbaa', 'params' => ['arg1' => 'a', 'arg2' => 'bb'], 'slots' => $slots], [])->andReturn(app('view'));
9797
View::shouldReceive('render')->once()->andReturn(implode(',', array_values($slots)));
9898

99-
foreach($slots as $name => $content) {
99+
foreach ($slots as $name => $content) {
100100
$renderer->startSlot($name);
101101
$renderer->renderSlot($content);
102-
ob_end_clean();
102+
ob_end_clean();
103103
}
104104

105105
//act
106106
$widget = new Widget4();
107107
$widget->controller = 'Widget4Ctrl@meta';
108108
$renderer->renderWidget($widget, ['arg1' => 'a', 'arg2' => 'bb']);
109109
}
110-
}
110+
}

0 commit comments

Comments
 (0)