From cf08be031327542e4aa4a85130111c4b218dbb8d Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Wed, 28 Nov 2012 22:10:28 +0000 Subject: [PATCH] Reducing some example code line lengths --- cookbook/doctrine/file_uploads.rst | 34 ++++++++++++++----- .../doctrine/multiple_entity_managers.rst | 19 ++++++----- cookbook/doctrine/registration_form.rst | 23 ++++++++++--- cookbook/email/dev_environment.rst | 13 ++++--- cookbook/email/email.rst | 7 +++- cookbook/testing/doctrine.rst | 5 ++- cookbook/testing/profiling.rst | 15 ++++++-- 7 files changed, 85 insertions(+), 31 deletions(-) diff --git a/cookbook/doctrine/file_uploads.rst b/cookbook/doctrine/file_uploads.rst index f23ab3cf57c..9cf46432b62 100644 --- a/cookbook/doctrine/file_uploads.rst +++ b/cookbook/doctrine/file_uploads.rst @@ -55,23 +55,29 @@ First, create a simple Doctrine Entity class to work with:: public function getAbsolutePath() { - return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path; + return null === $this->path + ? null + : $this->getUploadRootDir().'/'.$this->path; } public function getWebPath() { - return null === $this->path ? null : $this->getUploadDir().'/'.$this->path; + return null === $this->path + ? null + : $this->getUploadDir().'/'.$this->path; } protected function getUploadRootDir() { - // the absolute directory path where uploaded documents should be saved + // the absolute directory path where uploaded + // documents should be saved return __DIR__.'/../../../../web/'.$this->getUploadDir(); } protected function getUploadDir() { - // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view. + // get rid of the __DIR__ so it doesn't screw up + // when displaying uploaded doc/image in the view. return 'uploads/documents'; } } @@ -213,8 +219,12 @@ object, which is what's returned after a ``file`` field is submitted:: // use the original file name here but you should // sanitize it at least to avoid any security issues - // move takes the target directory and then the target filename to move to - $this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName()); + // move takes the target directory and then the + // target filename to move to + $this->file->move( + $this->getUploadRootDir(), + $this->file->getClientOriginalName() + ); // set the path property to the filename where you've saved the file $this->path = $this->file->getClientOriginalName(); @@ -266,7 +276,8 @@ Next, refactor the ``Document`` class to take advantage of these callbacks:: { if (null !== $this->file) { // do whatever you want to generate a unique name - $this->path = sha1(uniqid(mt_rand(), true)).'.'.$this->file->guessExtension(); + $filename = sha1(uniqid(mt_rand(), true)); + $this->path = $filename.'.'.$this->file->guessExtension(); } } @@ -373,7 +384,10 @@ property, instead of the actual filename:: // you must throw an exception here if the file cannot be moved // so that the entity is not persisted to the database // which the UploadedFile move() method does - $this->file->move($this->getUploadRootDir(), $this->id.'.'.$this->file->guessExtension()); + $this->file->move( + $this->getUploadRootDir(), + $this->id.'.'.$this->file->guessExtension() + ); unset($this->file); } @@ -398,7 +412,9 @@ property, instead of the actual filename:: public function getAbsolutePath() { - return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->id.'.'.$this->path; + return null === $this->path + ? null + : $this->getUploadRootDir().'/'.$this->id.'.'.$this->path; } } diff --git a/cookbook/doctrine/multiple_entity_managers.rst b/cookbook/doctrine/multiple_entity_managers.rst index 31823a93fd1..89c09465a32 100644 --- a/cookbook/doctrine/multiple_entity_managers.rst +++ b/cookbook/doctrine/multiple_entity_managers.rst @@ -64,7 +64,7 @@ two connections, one for each entity manager. .. note:: - When working with multiple connections and entity managers, you should be + When working with multiple connections and entity managers, you should be explicit about which configuration you want. If you *do* omit the name of the connection or entity manager, the default (i.e. ``default``) is used. @@ -98,7 +98,7 @@ the default entity manager (i.e. ``default``) is returned:: // both return the "default" em $em = $this->get('doctrine')->getManager(); $em = $this->get('doctrine')->getManager('default'); - + $customerEm = $this->get('doctrine')->getManager('customer'); } } @@ -115,17 +115,20 @@ The same applies to repository call:: { // Retrieves a repository managed by the "default" em $products = $this->get('doctrine') - ->getRepository('AcmeStoreBundle:Product') - ->findAll(); + ->getRepository('AcmeStoreBundle:Product') + ->findAll() + ; // Explicit way to deal with the "default" em $products = $this->get('doctrine') - ->getRepository('AcmeStoreBundle:Product', 'default') - ->findAll(); + ->getRepository('AcmeStoreBundle:Product', 'default') + ->findAll() + ; // Retrieves a repository managed by the "customer" em $customers = $this->get('doctrine') - ->getRepository('AcmeCustomerBundle:Customer', 'customer') - ->findAll(); + ->getRepository('AcmeCustomerBundle:Customer', 'customer') + ->findAll() + ; } } diff --git a/cookbook/doctrine/registration_form.rst b/cookbook/doctrine/registration_form.rst index b227f509e9c..fccd55ba97f 100644 --- a/cookbook/doctrine/registration_form.rst +++ b/cookbook/doctrine/registration_form.rst @@ -191,7 +191,11 @@ Next, create the form for this ``Registration`` model:: public function buildForm(FormBuilder $builder, array $options) { $builder->add('user', new UserType()); - $builder->add('terms', 'checkbox', array('property_path' => 'termsAccepted')); + $builder->add( + 'terms', + 'checkbox', + array('property_path' => 'termsAccepted') + ); } public function getName() @@ -224,9 +228,15 @@ controller for displaying the registration form:: { public function registerAction() { - $form = $this->createForm(new RegistrationType(), new Registration()); - - return $this->render('AcmeAccountBundle:Account:register.html.twig', array('form' => $form->createView())); + $form = $this->createForm( + new RegistrationType(), + new Registration() + ); + + return $this->render( + 'AcmeAccountBundle:Account:register.html.twig', + array('form' => $form->createView()) + ); } } @@ -261,7 +271,10 @@ the validation and saves the data into the database:: return $this->redirect(...); } - return $this->render('AcmeAccountBundle:Account:register.html.twig', array('form' => $form->createView())); + return $this->render( + 'AcmeAccountBundle:Account:register.html.twig', + array('form' => $form->createView()) + ); } That's it! Your form now validates, and allows you to save the ``User`` diff --git a/cookbook/email/dev_environment.rst b/cookbook/email/dev_environment.rst index 3ae234c4d54..ec798aefa21 100644 --- a/cookbook/email/dev_environment.rst +++ b/cookbook/email/dev_environment.rst @@ -96,7 +96,12 @@ Now, suppose you're sending an email to ``recipient@example.com``. ->setSubject('Hello Email') ->setFrom('send@example.com') ->setTo('recipient@example.com') - ->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name))) + ->setBody( + $this->renderView( + 'HelloBundle:Hello:email.txt.twig', + array('name' => $name) + ) + ) ; $this->get('mailer')->send($message); @@ -150,10 +155,10 @@ you to open the report with details of the sent emails. - setSubject('Hello Email') ->setFrom('send@example.com') ->setTo('recipient@example.com') - ->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name))) + ->setBody( + $this->renderView( + 'HelloBundle:Hello:email.txt.twig', + array('name' => $name) + ) + ) ; $this->get('mailer')->send($message); diff --git a/cookbook/testing/doctrine.rst b/cookbook/testing/doctrine.rst index fbffdac09b7..911fe816cb5 100644 --- a/cookbook/testing/doctrine.rst +++ b/cookbook/testing/doctrine.rst @@ -39,7 +39,10 @@ which makes all of this quite easy:: { static::$kernel = static::createKernel(); static::$kernel->boot(); - $this->em = static::$kernel->getContainer()->get('doctrine')->getEntityManager(); + $this->em = static::$kernel->getContainer() + ->get('doctrine') + ->getEntityManager() + ; } public function testSearchByCategoryName() diff --git a/cookbook/testing/profiling.rst b/cookbook/testing/profiling.rst index 14d1a9ebcbf..3e57fe19e74 100644 --- a/cookbook/testing/profiling.rst +++ b/cookbook/testing/profiling.rst @@ -27,10 +27,16 @@ environment):: // Check that the profiler is enabled if ($profile = $client->getProfile()) { // check the number of requests - $this->assertLessThan(10, $profile->getCollector('db')->getQueryCount()); + $this->assertLessThan( + 10, + $profile->getCollector('db')->getQueryCount() + ); // check the time spent in the framework - $this->assertLessThan(0.5, $profile->getCollector('timer')->getTime()); + $this->assertLessThan( + 0.5, + $profile->getCollector('timer')->getTime() + ); } } } @@ -42,7 +48,10 @@ finish. It's easy to achieve if you embed the token in the error message:: $this->assertLessThan( 30, $profile->get('db')->getQueryCount(), - sprintf('Checks that query count is less than 30 (token %s)', $profile->getToken()) + sprintf( + 'Checks that query count is less than 30 (token %s)', + $profile->getToken() + ) ); .. caution::