Skip to content

Reducing some example code line lengths #1988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions cookbook/doctrine/file_uploads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
}

Expand Down
19 changes: 11 additions & 8 deletions cookbook/doctrine/multiple_entity_managers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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');
}
}
Expand All @@ -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()
;
}
}
23 changes: 18 additions & 5 deletions cookbook/doctrine/registration_form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
);
}
}

Expand Down Expand Up @@ -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``
Expand Down
13 changes: 9 additions & 4 deletions cookbook/email/dev_environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -150,10 +155,10 @@ you to open the report with details of the sent emails.

<!-- app/config/config_dev.xml -->

<!--
<!--
xmlns:webprofiler="http://symfony.com/schema/dic/webprofiler"
xsi:schemaLocation="http://symfony.com/schema/dic/webprofiler
http://symfony.com/schema/dic/webprofiler/webprofiler-1.0.xsd">
xsi:schemaLocation="http://symfony.com/schema/dic/webprofiler
http://symfony.com/schema/dic/webprofiler/webprofiler-1.0.xsd">
-->

<webprofiler:config
Expand Down
7 changes: 6 additions & 1 deletion cookbook/email/email.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ an email is pretty straightforward::
->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);

Expand Down
5 changes: 4 additions & 1 deletion cookbook/testing/doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 12 additions & 3 deletions cookbook/testing/profiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
}
Expand All @@ -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::
Expand Down