Skip to content

Commit

Permalink
Minor refactoring and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kapxapot committed May 5, 2020
1 parent eee7f91 commit 6cf7851
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/Collections/Basic/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function toAssoc($by = null) : array
* Groups collection by column/property or callable.
*
* @param string|callable|null $by Column/property name or callable, returning generated column/property name.
* @return array<string, self>
* @return array<string, static>
*/
public function group($by = null) : array
{
Expand Down Expand Up @@ -561,4 +561,11 @@ public function toArray() : array
{
return $this->data;
}

// __toString()

public function __toString()
{
return get_class($this) . ' (' . $this->count() . ')';
}
}
9 changes: 6 additions & 3 deletions src/Models/DbModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function __call(string $name, array $args)
* Sets value for property 'x()' (use it in 'withX($x)' methods).
*
* @param mixed $value
* @return static
*/
protected function setWithProperty(string $name, $value) : self
{
Expand All @@ -137,9 +138,11 @@ protected function setWithProperty(string $name, $value) : self
protected function getWithProperty(string $name, bool $required = false)
{
if (array_key_exists($name, $this->with)) {
return isCallable($this->with[$name])
? ($this->with[$name])()
: $this->with[$name];
$withName = $this->with[$name];

return isCallable($withName)
? $withName()
: $withName;
}

$required = $required
Expand Down

0 comments on commit 6cf7851

Please sign in to comment.