Skip to content

Commit a2dd769

Browse files
committed
feature #45 Make setters fluent (elkuku)
This PR was squashed before being merged into the main branch. Discussion ---------- Make setters fluent | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Tickets | <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT I just replaced some charts in a personal project with ux-chartjs and it feels quite cool ;) To reduce local variables i'd love to see fluent setters. wdyt? Commits ------- 3c22ee0 Make setters fluent
2 parents b00e425 + 3c22ee0 commit a2dd769

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/Chartjs/Model/Chart.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,34 @@ public function __construct(string $type)
3838
$this->type = $type;
3939
}
4040

41-
public function setData(array $data)
41+
/**
42+
* @return $this
43+
*/
44+
public function setData(array $data): self
4245
{
4346
$this->data = $data;
47+
48+
return $this;
4449
}
4550

46-
public function setOptions(array $options)
51+
/**
52+
* @return $this
53+
*/
54+
public function setOptions(array $options): self
4755
{
4856
$this->options = $options;
57+
58+
return $this;
4959
}
5060

51-
public function setAttributes(array $attributes)
61+
/**
62+
* @return $this
63+
*/
64+
public function setAttributes(array $attributes): self
5265
{
5366
$this->attributes = $attributes;
67+
68+
return $this;
5469
}
5570

5671
public function createView(): array

src/Cropperjs/Model/Crop.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,38 @@ public function getOptions(): string
107107
return json_encode($this->options);
108108
}
109109

110-
public function setOptions(string $options)
110+
/**
111+
* @return $this
112+
*/
113+
public function setOptions(string $options): self
111114
{
112115
$this->options = json_decode($options, true);
116+
117+
return $this;
113118
}
114119

115-
public function setDefaultOptions(array $options)
120+
/**
121+
* @return $this
122+
*/
123+
public function setDefaultOptions(array $options): self
116124
{
117125
foreach ($this->options as $key => $defaultValue) {
118126
if (isset($options[$key])) {
119127
$this->options[$key] = $options[$key];
120128
}
121129
}
130+
131+
return $this;
122132
}
123133

124-
public function setCroppedMaxSize(int $maxWidth, int $maxHeight)
134+
/**
135+
* @return $this
136+
*/
137+
public function setCroppedMaxSize(int $maxWidth, int $maxHeight): self
125138
{
126139
$this->maxWidth = $maxWidth;
127140
$this->maxHeight = $maxHeight;
141+
142+
return $this;
128143
}
129144
}

0 commit comments

Comments
 (0)