Skip to content

Commit 5ae6020

Browse files
lrljoegithub-actions[bot]
authored andcommitted
Fix styling
1 parent a172fd1 commit 5ae6020

File tree

5 files changed

+53
-88
lines changed

5 files changed

+53
-88
lines changed

src/Views/Columns/LivewireComponentColumn.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@ class LivewireComponentColumn extends Column
1818

1919
/**
2020
* The Livewire Component assigned to this Column
21-
*
22-
* @var string|null
2321
*/
2422
protected ?string $livewireComponent;
2523

2624
/**
2725
* Gets the contents for current row
28-
*
29-
* @param Model $row
30-
* @return null|string|HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
3126
*/
3227
public function getContents(Model $row): null|string|HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
3328
{
3429
$this->runPreChecks();
35-
30+
3631
$attributes = $this->retrieveAttributes($row);
3732

38-
return $this->getHtmlString($attributes, $this->getTable()."-".$row->{$row->getKeyName()});
33+
return $this->getHtmlString($attributes, $this->getTable().'-'.$row->{$row->getKeyName()});
3934

4035
}
4136
}

src/Views/Columns/Traits/Configuration/LivewireComponentColumnConfiguration.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66

77
trait LivewireComponentColumnConfiguration
88
{
9-
109
/**
1110
* Defines which component to use
12-
*
13-
* @param string $livewireComponent
14-
* @return self
1511
*/
1612
public function component(string $livewireComponent): self
1713
{

src/Views/Columns/Traits/Helpers/LivewireComponentColumnHelpers.php

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,31 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Views\Columns\Traits\Helpers;
44

5-
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
65
use Illuminate\Database\Eloquent\Model;
76
use Illuminate\Support\Facades\Blade;
87
use Illuminate\Support\HtmlString;
8+
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
99

1010
trait LivewireComponentColumnHelpers
1111
{
12-
1312
/**
1413
* Retrieves the defined Component View
15-
*
16-
* @return string|null
17-
*/
14+
*/
1815
public function getLivewireComponent(): ?string
1916
{
2017
return $this->livewireComponent ?? null;
2118
}
2219

23-
2420
/**
2521
* Determines whether a Livewire Component has been set
26-
*
27-
* @return boolean
28-
*/
22+
*/
2923
public function hasLivewireComponent(): bool
3024
{
3125
return isset($this->livewireComponent);
3226
}
3327

3428
/**
3529
* Retrieves attributes based on callback
36-
*
37-
* @param Model $row
38-
* @return array
3930
*/
4031
protected function retrieveAttributes(Model $row): array
4132
{
@@ -50,48 +41,43 @@ protected function retrieveAttributes(Model $row): array
5041
throw new DataTableConfigurationException('The return type of callback must be an array');
5142
}
5243
}
44+
5345
return $attributes;
5446
}
5547

5648
/**
5749
* Runs pre-checks
58-
*
59-
* @return boolean
6050
*/
6151
protected function runPreChecks(): bool
6252
{
6353
if (! $this->hasLivewireComponent()) {
6454
throw new DataTableConfigurationException('You must define a Livewire Component for this column');
55+
6556
return false;
6657
}
6758

6859
if ($this->isLabel()) {
6960
throw new DataTableConfigurationException('You can not use a label column with a Livewire Component column');
61+
7062
return false;
7163
}
7264

7365
return true;
7466
}
7567

7668
/**
77-
* Implodes defined attributes to be used
78-
*
79-
* @param array $attributes
80-
* @return string
81-
*/
69+
* Implodes defined attributes to be used
70+
*/
8271
protected function implodeAttributes(array $attributes): string
8372
{
8473
return collect($attributes)->map(function ($value, $key) {
8574
return ':'.$key.'="$'.$key.'"';
8675
})->implode(' ');
8776
}
8877

89-
/**
90-
* getBlade Render
91-
*
92-
* @param array $attributes
93-
* @param string $key
94-
*/
78+
/**
79+
* getBlade Render
80+
*/
9581
protected function getBlade(array $attributes, string $key)
9682
{
9783
return Blade::render(
@@ -106,17 +92,10 @@ protected function getBlade(array $attributes, string $key)
10692

10793
/**
10894
* Gets HTML STring
109-
*
110-
* @param array $attributes
111-
* @param string $key
112-
* @return HtmlString
11395
*/
114-
protected function getHtmlString(array $attributes, string $key): HtmlString
96+
protected function getHtmlString(array $attributes, string $key): HtmlString
11597
{
11698
return new HtmlString($this->getBlade($attributes, $key));
11799

118100
}
119-
120-
121-
122101
}
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
<?php
2-
3-
namespace Rappasoft\LaravelLivewireTables\Tests\Http;
4-
5-
use Closure;
6-
use Illuminate\Contracts\View\View;
7-
use Illuminate\View\Component;
8-
9-
class TestComponent extends Component
10-
{
11-
public int $testItem = 0;
12-
13-
public function __construct(int $age)
14-
{
15-
$this->testItem = $age * 110;
16-
}
17-
18-
/**
19-
* Get the view / contents that represent the component.
20-
*/
21-
public function render(): View|Closure|string
22-
{
23-
return \Illuminate\Support\Facades\Blade::render(
24-
'<div>'.($this->testItem ?? 'Unknown').'</div>');
25-
26-
}
27-
}
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Http;
4+
5+
use Closure;
6+
use Illuminate\Contracts\View\View;
7+
use Illuminate\View\Component;
8+
9+
class TestComponent extends Component
10+
{
11+
public int $testItem = 0;
12+
13+
public function __construct(int $age)
14+
{
15+
$this->testItem = $age * 110;
16+
}
17+
18+
/**
19+
* Get the view / contents that represent the component.
20+
*/
21+
public function render(): View|Closure|string
22+
{
23+
return \Illuminate\Support\Facades\Blade::render(
24+
'<div>'.($this->testItem ?? 'Unknown').'</div>');
25+
26+
}
27+
}

tests/Unit/Views/Columns/LivewireComponentColumnTest.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Columns;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use PHPUnit\Framework\Attributes\Group;
67
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
78
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet;
89
use Rappasoft\LaravelLivewireTables\Views\Column;
910
use Rappasoft\LaravelLivewireTables\Views\Columns\LivewireComponentColumn;
10-
use Illuminate\Database\Eloquent\Model;
1111

1212
#[Group('Columns')]
1313
final class LivewireComponentColumnTest extends ColumnTestCase
@@ -97,9 +97,8 @@ public static function setup_with_public_methods()
9797

9898
$row = Pet::find(1);
9999

100-
$temp = (new class("name", "name") extends LivewireComponentColumn
100+
$temp = (new class('name', 'name') extends LivewireComponentColumn
101101
{
102-
103102
public function pubRetrieveAttributes(Model $row)
104103
{
105104
return $this->retrieveAttributes($row);
@@ -112,17 +111,16 @@ public function pubImplodeAttributes(array $attributes)
112111

113112
public function pubGetBlade(array $attributes, string $key)
114113
{
115-
return $this->getBlade($attributes,$key);
114+
return $this->getBlade($attributes, $key);
116115
}
117116

118117
public function pubGetHtmlString(array $attributes, string $key)
119118
{
120-
return $this->getHtmlString($attributes,$key);
119+
return $this->getHtmlString($attributes, $key);
121120
}
122-
123121
})->component('test-component')->attributes(function ($columnValue, $row) {
124122
return [
125-
'type' => "test",
123+
'type' => 'test',
126124
'name' => $row->name,
127125
];
128126
});
@@ -132,12 +130,11 @@ public function pubGetHtmlString(array $attributes, string $key)
132130
return $temp;
133131
}
134132

135-
136133
public function test_can_get_attributes_correctly(): void
137134
{
138135
$row = Pet::find(1);
139136
$temp = self::setup_with_public_methods();
140-
$key = "test-table-".$row->{$row->getKeyName()};
137+
$key = 'test-table-'.$row->{$row->getKeyName()};
141138

142139
$this->assertSame(['type' => 'test', 'name' => 'Cartman'], $temp->pubRetrieveAttributes($row));
143140

@@ -148,21 +145,19 @@ public function test_can_get_blade_correctly(): void
148145
{
149146
$row = Pet::find(1);
150147
$temp = self::setup_with_public_methods();
151-
$key = "test-table-".$row->{$row->getKeyName()};
148+
$key = 'test-table-'.$row->{$row->getKeyName()};
149+
150+
$this->assertStringContainsString('wire:snapshot="{&quot;data&quot;:{&quot;id&quot;:null,&quot;name&quot;:&quot;Cartman&quot;,&quot;value&quot;:null,&quot;type&quot;:&quot;test&quot;}', $temp->pubGetBlade($temp->pubRetrieveAttributes($row), $key));
152151

153-
$this->assertStringContainsString('wire:snapshot="{&quot;data&quot;:{&quot;id&quot;:null,&quot;name&quot;:&quot;Cartman&quot;,&quot;value&quot;:null,&quot;type&quot;:&quot;test&quot;}', $temp->pubGetBlade($temp->pubRetrieveAttributes($row),$key));
154-
155-
$this->assertStringContainsString('<div>Name:Cartman</div><div>Type:test</div>', $temp->pubGetBlade($temp->pubRetrieveAttributes($row),$key));
152+
$this->assertStringContainsString('<div>Name:Cartman</div><div>Type:test</div>', $temp->pubGetBlade($temp->pubRetrieveAttributes($row), $key));
156153
}
157154

158155
public function test_can_get_html_string_correctly(): void
159156
{
160157
$row = Pet::find(1);
161158
$temp = self::setup_with_public_methods();
162-
$key = "test-table-".$row->{$row->getKeyName()};
159+
$key = 'test-table-'.$row->{$row->getKeyName()};
163160

164-
$this->assertStringContainsString('<div>Name:Cartman</div><div>Type:test</div>', $temp->pubGetHtmlString($temp->pubRetrieveAttributes($row),$key));
161+
$this->assertStringContainsString('<div>Name:Cartman</div><div>Type:test</div>', $temp->pubGetHtmlString($temp->pubRetrieveAttributes($row), $key));
165162
}
166-
167163
}
168-

0 commit comments

Comments
 (0)