-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ray-di/entity-with-constructor
Support entity constructor
- Loading branch information
Showing
13 changed files
with
3,000 additions
and
1,704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\MediaQuery; | ||
|
||
use function lcfirst; | ||
use function str_replace; | ||
use function ucwords; | ||
|
||
trait CamelCaseTrait | ||
{ | ||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __set(string $name, $value): void | ||
{ | ||
$propName = lcfirst(str_replace('_', '', ucwords($name, '_'))); | ||
$this->{$propName} = $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\MediaQuery; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Ray\MediaQuery\Entity\Invoice; | ||
|
||
class CamelCaseTraitTest extends TestCase | ||
{ | ||
public function testRequest(): void | ||
{ | ||
$user = new Invoice(); | ||
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps | ||
$user->user_name = '1'; // @phpstan-ignore-line | ||
$this->assertSame($user->userName, '1'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\MediaQuery\Entity; | ||
|
||
use Ray\MediaQuery\CamelCaseTrait; | ||
|
||
class Invoice | ||
{ | ||
use CamelCaseTrait; | ||
|
||
/** @var string */ | ||
public $userName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ray\MediaQuery\Entity; | ||
|
||
class TodoConstruct | ||
{ | ||
/** @var string */ | ||
public $id; | ||
|
||
/** @var string */ | ||
public $title; | ||
|
||
public function __construct(string $id, string $title) | ||
{ | ||
$this->id = $id; | ||
$this->title = $title; | ||
} | ||
} |
Oops, something went wrong.