PHP code example of object-calisthenics / phpcs-calisthenics-rules
1. Go to this page and download the library: Download object-calisthenics/phpcs-calisthenics-rules library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
object-calisthenics / phpcs-calisthenics-rules example snippets
foreach ($sniffGroups as $sniffGroup) {
foreach ($sniffGroup as $sniffKey => $sniffClass) {
if (! $sniffClass instanceof Sniff) {
throw new InvalidClassTypeException;
}
}
}
foreach ($sniffGroups as $sniffGroup) {
$this->ensureIsAllInstanceOf($sniffGroup, Sniff::class);
}
// ...
private function ensureIsAllInstanceOf(array $objects, string $type)
{
// ...
}
if ($status === self::DONE) {
$this->finish();
} else {
$this->advance();
}
if ($status === self::DONE) {
$this->finish();
return;
}
$this->advance();
$this->container->getBuilder()->addDefinition(SniffRunner::class);
$containerBuilder = $this->getContainerBuilder();
$containerBuilder->addDefinition(SniffRunner::class);
class EM
{
// ...
}
class EntityMailer
{
// ...
}
class SimpleStartupController
{
// 300 lines of code
}
class SimpleStartupController
{
// 50 lines of code
}
class SomeClass
{
public function simpleLogic()
{
// 30 lines of code
}
}
class SomeClass
{
public function simpleLogic()
{
// 10 lines of code
}
}
class SomeClass
{
// 20 properties
}
class SomeClass
{
// 5 properties
}
class SomeClass
{
// 20 methods
}
class SomeClass
{
// 5 methods
}
class ImmutableBankAccount
{
public $currency = 'USD';
private $amount;
public function setAmount(int $amount)
{
$this->amount = $amount;
}
}
class ImmutableBankAccount
{
private $currency = 'USD';
private $amount;
public function withdrawAmount(int $withdrawnAmount)
{
$this->amount -= $withdrawnAmount;
}
}