From 87d904638953a1b7b3825347ef055a384bbc555b Mon Sep 17 00:00:00 2001 From: Marko Kunic Date: Sun, 11 Mar 2018 15:46:53 +0100 Subject: [PATCH] improve naming --- best_practices/business-logic.rst | 2 +- best_practices/templates.rst | 4 +--- components/form.rst | 2 +- components/serializer.rst | 12 ++++++------ console/commands_as_services.rst | 3 +-- controller/soap_web_service.rst | 2 +- event_dispatcher/class_extension.rst | 4 ++-- form/unit_testing.rst | 6 +++--- routing/custom_route_loader.rst | 6 +++--- security/custom_authentication_provider.rst | 18 +++++++++--------- security/custom_password_authenticator.rst | 6 +++--- security/expressions.rst | 6 +++--- security/guard_authentication.rst | 4 ++-- 13 files changed, 36 insertions(+), 39 deletions(-) diff --git a/best_practices/business-logic.rst b/best_practices/business-logic.rst index d25a457314b..83d85e73566 100644 --- a/best_practices/business-logic.rst +++ b/best_practices/business-logic.rst @@ -211,7 +211,7 @@ looking for mapping information:: */ class Post { - const NUM_ITEMS = 10; + const NUMBER_OF_ITEMS = 10; /** * @ORM\Id diff --git a/best_practices/templates.rst b/best_practices/templates.rst index 26219bf815b..dd3ba3e770f 100644 --- a/best_practices/templates.rst +++ b/best_practices/templates.rst @@ -107,9 +107,7 @@ Markdown content into HTML:: public function toHtml($text) { - $html = $this->parser->text($text); - - return $html; + return $this->parser->text($text); } } diff --git a/components/form.rst b/components/form.rst index 3ad2737484f..9213936f8b2 100644 --- a/components/form.rst +++ b/components/form.rst @@ -307,7 +307,7 @@ Your integration with the Validation component will look something like this:: use Symfony\Component\Validator\Validation; $vendorDirectory = realpath(__DIR__.'/../vendor'); - $vendorFormDirectory = $vendorDir.'/symfony/form'; + $vendorFormDirectory = $vendorDirectory.'/symfony/form'; $vendorValidatorDirectory = $vendorDirectory.'/symfony/validator'; // creates the validator - details will vary diff --git a/components/serializer.rst b/components/serializer.rst index af09062a377..ff0163b7c0f 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -407,14 +407,14 @@ and :class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`:: $serializer = new Serializer(array($normalizer), array(new JsonEncoder())); - $obj = new Company(); - $obj->name = 'Acme Inc.'; - $obj->address = '123 Main Street, Big City'; + $company = new Company(); + $company->name = 'Acme Inc.'; + $company->address = '123 Main Street, Big City'; - $json = $serializer->serialize($obj, 'json'); + $json = $serializer->serialize($company, 'json'); // {"org_name": "Acme Inc.", "org_address": "123 Main Street, Big City"} - $objCopy = $serializer->deserialize($json, Company::class, 'json'); - // Same data as $obj + $companyCopy = $serializer->deserialize($json, Company::class, 'json'); + // Same data as $company .. _using-camelized-method-names-for-underscored-attributes: diff --git a/console/commands_as_services.rst b/console/commands_as_services.rst index 12bfb0cbffb..90555f570ec 100644 --- a/console/commands_as_services.rst +++ b/console/commands_as_services.rst @@ -98,7 +98,6 @@ store the default value in some ``%command.default_name%`` parameter:: { // try to avoid work here (e.g. database query) // this method is *always* called - see warning below - $defaultName = $this->defaultName; $this ->setName('demo:greet') @@ -108,7 +107,7 @@ store the default value in some ``%command.default_name%`` parameter:: '-n', InputOption::VALUE_REQUIRED, 'Who do you want to greet?', - $defaultName + $this->defaultName ) ; } diff --git a/controller/soap_web_service.rst b/controller/soap_web_service.rst index 00ae10c083f..5a253a0c1b8 100644 --- a/controller/soap_web_service.rst +++ b/controller/soap_web_service.rst @@ -131,7 +131,7 @@ Below is an example calling the service using a `NuSOAP`_ client. This example assumes that the ``indexAction()`` in the controller above is accessible via the route ``/soap``:: - $soapClient = new \Soapclient('http://example.com/app.php/soap?wsdl'); + $soapClient = new \SoapClient('http://example.com/app.php/soap?wsdl'); $result = $soapClient->call('hello', array('name' => 'Scott')); diff --git a/event_dispatcher/class_extension.rst b/event_dispatcher/class_extension.rst index 776ee1b92e1..382c8dcf970 100644 --- a/event_dispatcher/class_extension.rst +++ b/event_dispatcher/class_extension.rst @@ -66,9 +66,9 @@ use this pattern of class extension:: /** * Sets the value to return and stops other listeners from being notified */ - public function setReturnValue($val) + public function setReturnValue($returnValue) { - $this->returnValue = $val; + $this->returnValue = $returnValue; $this->isProcessed = true; $this->stopPropagation(); } diff --git a/form/unit_testing.rst b/form/unit_testing.rst index 4d41b871a0e..26cca06009c 100644 --- a/form/unit_testing.rst +++ b/form/unit_testing.rst @@ -131,12 +131,12 @@ make sure the ``FormRegistry`` uses the created instance:: class TestedTypeTest extends TypeTestCase { - private $entityManager; + private $objectManager; protected function setUp() { // mock any dependencies - $this->entityManager = $this->createMock(ObjectManager::class); + $this->objectManager = $this->createMock(ObjectManager::class); parent::setUp(); } @@ -144,7 +144,7 @@ make sure the ``FormRegistry`` uses the created instance:: protected function getExtensions() { // create a type instance with the mocked dependencies - $type = new TestedType($this->entityManager); + $type = new TestedType($this->objectManager); return array( // register the type instances with the PreloadedExtension diff --git a/routing/custom_route_loader.rst b/routing/custom_route_loader.rst index d607f11606e..1ab7a49d755 100644 --- a/routing/custom_route_loader.rst +++ b/routing/custom_route_loader.rst @@ -98,12 +98,12 @@ and configure the service and method to call: // app/config/routing.php use Symfony\Component\Routing\RouteCollection; - $collection = new RouteCollection(); - $collection->addCollection( + $routes = new RouteCollection(); + $routes->addCollection( $loader->import("admin_route_loader:loadRoutes", "service") ); - return $collection; + return $routes; In this example, the routes are loaded by calling the ``loadRoutes()`` method of the service whose ID is ``admin_route_loader``. Your service doesn't have to diff --git a/security/custom_authentication_provider.rst b/security/custom_authentication_provider.rst index fa9ec0fc103..5ada9fd6db5 100644 --- a/security/custom_authentication_provider.rst +++ b/security/custom_authentication_provider.rst @@ -212,12 +212,12 @@ the ``PasswordDigest`` header value matches with the user's password:: class WsseProvider implements AuthenticationProviderInterface { private $userProvider; - private $cacheDir; + private $cacheDirectory; - public function __construct(UserProviderInterface $userProvider, $cacheDir) + public function __construct(UserProviderInterface $userProvider, $cacheDirectory) { - $this->userProvider = $userProvider; - $this->cacheDir = $cacheDir; + $this->userProvider = $userProvider; + $this->cacheDirectory = $cacheDirectory; } public function authenticate(TokenInterface $token) @@ -255,16 +255,16 @@ the ``PasswordDigest`` header value matches with the user's password:: // Validate that the nonce is *not* used in the last 5 minutes // if it has, this could be a replay attack if ( - file_exists($this->cacheDir.'/'.md5($nonce)) - && file_get_contents($this->cacheDir.'/'.md5($nonce)) + 300 > time() + file_exists($this->cacheDirectory.'/'.md5($nonce)) + && file_get_contents($this->cacheDirectory.'/'.md5($nonce)) + 300 > time() ) { throw new NonceExpiredException('Previously used nonce detected'); } // If cache directory does not exist we create it - if (!is_dir($this->cacheDir)) { - mkdir($this->cacheDir, 0777, true); + if (!is_dir($this->cacheDirectory)) { + mkdir($this->cacheDirectory, 0777, true); } - file_put_contents($this->cacheDir.'/'.md5($nonce), time()); + file_put_contents($this->cacheDirectory.'/'.md5($nonce), time()); // Validate Secret $expected = base64_encode(sha1(base64_decode($nonce).$created.$secret, true)); diff --git a/security/custom_password_authenticator.rst b/security/custom_password_authenticator.rst index ed2a812c459..03b816a7128 100644 --- a/security/custom_password_authenticator.rst +++ b/security/custom_password_authenticator.rst @@ -58,9 +58,9 @@ the user:: throw new CustomUserMessageAuthenticationException('Invalid username or password'); } - $passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials()); + $isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials()); - if ($passwordValid) { + if ($isPasswordValid) { $currentHour = date('G'); if ($currentHour < 14 || $currentHour > 16) { // CAUTION: this message will be returned to the client @@ -142,7 +142,7 @@ inside of it. Inside this method, the password encoder is needed to check the password's validity:: - $passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials()); + $isPasswordValid = $this->encoder->isPasswordValid($user, $token->getCredentials()); This is a service that is already available in Symfony and it uses the password algorithm that is configured in the security configuration (e.g. ``security.yml``) under diff --git a/security/expressions.rst b/security/expressions.rst index e9ea4fdb6b8..6d946e2523d 100644 --- a/security/expressions.rst +++ b/security/expressions.rst @@ -75,10 +75,10 @@ Additionally, you have access to a number of functions inside the expression: use Symfony\Component\ExpressionLanguage\Expression; // ... - $ac = $this->get('security.authorization_checker'); - $access1 = $ac->isGranted('IS_AUTHENTICATED_REMEMBERED'); + $authorizationChecker = $this->get('security.authorization_checker'); + $access1 = $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED'); - $access2 = $ac->isGranted(new Expression( + $access2 = $authorizationChecker->isGranted(new Expression( 'is_remember_me() or is_fully_authenticated()' )); diff --git a/security/guard_authentication.rst b/security/guard_authentication.rst index def6fdcbf6b..6c2a521ff9f 100644 --- a/security/guard_authentication.rst +++ b/security/guard_authentication.rst @@ -442,8 +442,8 @@ Customizing Error Messages -------------------------- When ``onAuthenticationFailure()`` is called, it is passed an ``AuthenticationException`` -that describes *how* authentication failed via its ``$e->getMessageKey()`` (and -``$e->getMessageData()``) method. The message will be different based on *where* +that describes *how* authentication failed via its ``$exception->getMessageKey()`` (and +``$exception->getMessageData()``) method. The message will be different based on *where* authentication fails (i.e. ``getUser()`` versus ``checkCredentials()``). But, you can easily return a custom message by throwing a