Skip to content

Commit

Permalink
Avoiding a hard coded class name in a static calls
Browse files Browse the repository at this point in the history
  • Loading branch information
grikdotnet committed Dec 8, 2020
1 parent c9a82b3 commit 149a910
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/acme-image/src/ImageService.php
Expand Up @@ -48,4 +48,12 @@ public function doFoo(): mixed
return $this->imageLib->foo();
}

/**
* Example of adding the static method to the public API
* @return int
*/
public static function answerUltimateQuestion(): int
{
return Image::answerUltimateQuestion();
}
}
3 changes: 2 additions & 1 deletion src/ImageResizeController.php
Expand Up @@ -14,7 +14,8 @@ public function __construct(public ImageInterface $image)

public function action(?string $id)
{
$answer = Acme\Image\lib\Image::answerUltimateQuestion();
//now the code is not bound to the Acme\Image\lib\Image class
$answer = $this->image::answerUltimateQuestion();
$this->image->load($id);
}
}

0 comments on commit 149a910

Please sign in to comment.