1. Go to this page and download the library: Download simtel/rector-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/ */
simtel / rector-rules example snippets
class UserRepository
{
public function findUserById(int $id): User
{
// Always returns User, never null
return $this->entityManager->find(User::class, $id)
?? throw new UserNotFoundException();
}
public function findUserByEmail(string $email): ?User
{
// May return null
return $this->entityManager->getRepository(User::class)
->findOneBy(['email' => $email]);
}
}
class UserRepository
{
public function getUserById(int $id): User // Renamed find -> get
{
// Always returns User, never null
return $this->entityManager->find(User::class, $id)
?? throw new UserNotFoundException();
}
public function findUserByEmail(string $email): ?User // Unchanged (nullable)
{
// May return null
return $this->entityManager->getRepository(User::class)
->findOneBy(['email' => $email]);
}
}