Skip to content

Commit cf08be0

Browse files
Reducing some example code line lengths
1 parent 114ce6d commit cf08be0

File tree

7 files changed

+85
-31
lines changed

7 files changed

+85
-31
lines changed

cookbook/doctrine/file_uploads.rst

+25-9
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,29 @@ First, create a simple Doctrine Entity class to work with::
5555

5656
public function getAbsolutePath()
5757
{
58-
return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path;
58+
return null === $this->path
59+
? null
60+
: $this->getUploadRootDir().'/'.$this->path;
5961
}
6062

6163
public function getWebPath()
6264
{
63-
return null === $this->path ? null : $this->getUploadDir().'/'.$this->path;
65+
return null === $this->path
66+
? null
67+
: $this->getUploadDir().'/'.$this->path;
6468
}
6569

6670
protected function getUploadRootDir()
6771
{
68-
// the absolute directory path where uploaded documents should be saved
72+
// the absolute directory path where uploaded
73+
// documents should be saved
6974
return __DIR__.'/../../../../web/'.$this->getUploadDir();
7075
}
7176

7277
protected function getUploadDir()
7378
{
74-
// get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
79+
// get rid of the __DIR__ so it doesn't screw up
80+
// when displaying uploaded doc/image in the view.
7581
return 'uploads/documents';
7682
}
7783
}
@@ -213,8 +219,12 @@ object, which is what's returned after a ``file`` field is submitted::
213219
// use the original file name here but you should
214220
// sanitize it at least to avoid any security issues
215221

216-
// move takes the target directory and then the target filename to move to
217-
$this->file->move($this->getUploadRootDir(), $this->file->getClientOriginalName());
222+
// move takes the target directory and then the
223+
// target filename to move to
224+
$this->file->move(
225+
$this->getUploadRootDir(),
226+
$this->file->getClientOriginalName()
227+
);
218228

219229
// set the path property to the filename where you've saved the file
220230
$this->path = $this->file->getClientOriginalName();
@@ -266,7 +276,8 @@ Next, refactor the ``Document`` class to take advantage of these callbacks::
266276
{
267277
if (null !== $this->file) {
268278
// do whatever you want to generate a unique name
269-
$this->path = sha1(uniqid(mt_rand(), true)).'.'.$this->file->guessExtension();
279+
$filename = sha1(uniqid(mt_rand(), true));
280+
$this->path = $filename.'.'.$this->file->guessExtension();
270281
}
271282
}
272283

@@ -373,7 +384,10 @@ property, instead of the actual filename::
373384
// you must throw an exception here if the file cannot be moved
374385
// so that the entity is not persisted to the database
375386
// which the UploadedFile move() method does
376-
$this->file->move($this->getUploadRootDir(), $this->id.'.'.$this->file->guessExtension());
387+
$this->file->move(
388+
$this->getUploadRootDir(),
389+
$this->id.'.'.$this->file->guessExtension()
390+
);
377391

378392
unset($this->file);
379393
}
@@ -398,7 +412,9 @@ property, instead of the actual filename::
398412

399413
public function getAbsolutePath()
400414
{
401-
return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->id.'.'.$this->path;
415+
return null === $this->path
416+
? null
417+
: $this->getUploadRootDir().'/'.$this->id.'.'.$this->path;
402418
}
403419
}
404420

cookbook/doctrine/multiple_entity_managers.rst

+11-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ two connections, one for each entity manager.
6464

6565
.. note::
6666

67-
When working with multiple connections and entity managers, you should be
67+
When working with multiple connections and entity managers, you should be
6868
explicit about which configuration you want. If you *do* omit the name of
6969
the connection or entity manager, the default (i.e. ``default``) is used.
7070

@@ -98,7 +98,7 @@ the default entity manager (i.e. ``default``) is returned::
9898
// both return the "default" em
9999
$em = $this->get('doctrine')->getManager();
100100
$em = $this->get('doctrine')->getManager('default');
101-
101+
102102
$customerEm = $this->get('doctrine')->getManager('customer');
103103
}
104104
}
@@ -115,17 +115,20 @@ The same applies to repository call::
115115
{
116116
// Retrieves a repository managed by the "default" em
117117
$products = $this->get('doctrine')
118-
->getRepository('AcmeStoreBundle:Product')
119-
->findAll();
118+
->getRepository('AcmeStoreBundle:Product')
119+
->findAll()
120+
;
120121

121122
// Explicit way to deal with the "default" em
122123
$products = $this->get('doctrine')
123-
->getRepository('AcmeStoreBundle:Product', 'default')
124-
->findAll();
124+
->getRepository('AcmeStoreBundle:Product', 'default')
125+
->findAll()
126+
;
125127

126128
// Retrieves a repository managed by the "customer" em
127129
$customers = $this->get('doctrine')
128-
->getRepository('AcmeCustomerBundle:Customer', 'customer')
129-
->findAll();
130+
->getRepository('AcmeCustomerBundle:Customer', 'customer')
131+
->findAll()
132+
;
130133
}
131134
}

cookbook/doctrine/registration_form.rst

+18-5
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ Next, create the form for this ``Registration`` model::
191191
public function buildForm(FormBuilder $builder, array $options)
192192
{
193193
$builder->add('user', new UserType());
194-
$builder->add('terms', 'checkbox', array('property_path' => 'termsAccepted'));
194+
$builder->add(
195+
'terms',
196+
'checkbox',
197+
array('property_path' => 'termsAccepted')
198+
);
195199
}
196200

197201
public function getName()
@@ -224,9 +228,15 @@ controller for displaying the registration form::
224228
{
225229
public function registerAction()
226230
{
227-
$form = $this->createForm(new RegistrationType(), new Registration());
228-
229-
return $this->render('AcmeAccountBundle:Account:register.html.twig', array('form' => $form->createView()));
231+
$form = $this->createForm(
232+
new RegistrationType(),
233+
new Registration()
234+
);
235+
236+
return $this->render(
237+
'AcmeAccountBundle:Account:register.html.twig',
238+
array('form' => $form->createView())
239+
);
230240
}
231241
}
232242

@@ -261,7 +271,10 @@ the validation and saves the data into the database::
261271
return $this->redirect(...);
262272
}
263273

264-
return $this->render('AcmeAccountBundle:Account:register.html.twig', array('form' => $form->createView()));
274+
return $this->render(
275+
'AcmeAccountBundle:Account:register.html.twig',
276+
array('form' => $form->createView())
277+
);
265278
}
266279

267280
That's it! Your form now validates, and allows you to save the ``User``

cookbook/email/dev_environment.rst

+9-4
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ Now, suppose you're sending an email to ``recipient@example.com``.
9696
->setSubject('Hello Email')
9797
->setFrom('send@example.com')
9898
->setTo('recipient@example.com')
99-
->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name)))
99+
->setBody(
100+
$this->renderView(
101+
'HelloBundle:Hello:email.txt.twig',
102+
array('name' => $name)
103+
)
104+
)
100105
;
101106
$this->get('mailer')->send($message);
102107
@@ -150,10 +155,10 @@ you to open the report with details of the sent emails.
150155
151156
<!-- app/config/config_dev.xml -->
152157
153-
<!--
158+
<!--
154159
xmlns:webprofiler="http://symfony.com/schema/dic/webprofiler"
155-
xsi:schemaLocation="http://symfony.com/schema/dic/webprofiler
156-
http://symfony.com/schema/dic/webprofiler/webprofiler-1.0.xsd">
160+
xsi:schemaLocation="http://symfony.com/schema/dic/webprofiler
161+
http://symfony.com/schema/dic/webprofiler/webprofiler-1.0.xsd">
157162
-->
158163
159164
<webprofiler:config

cookbook/email/email.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ an email is pretty straightforward::
106106
->setSubject('Hello Email')
107107
->setFrom('send@example.com')
108108
->setTo('recipient@example.com')
109-
->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name)))
109+
->setBody(
110+
$this->renderView(
111+
'HelloBundle:Hello:email.txt.twig',
112+
array('name' => $name)
113+
)
114+
)
110115
;
111116
$this->get('mailer')->send($message);
112117

cookbook/testing/doctrine.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ which makes all of this quite easy::
3939
{
4040
static::$kernel = static::createKernel();
4141
static::$kernel->boot();
42-
$this->em = static::$kernel->getContainer()->get('doctrine')->getEntityManager();
42+
$this->em = static::$kernel->getContainer()
43+
->get('doctrine')
44+
->getEntityManager()
45+
;
4346
}
4447

4548
public function testSearchByCategoryName()

cookbook/testing/profiling.rst

+12-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ environment)::
2727
// Check that the profiler is enabled
2828
if ($profile = $client->getProfile()) {
2929
// check the number of requests
30-
$this->assertLessThan(10, $profile->getCollector('db')->getQueryCount());
30+
$this->assertLessThan(
31+
10,
32+
$profile->getCollector('db')->getQueryCount()
33+
);
3134

3235
// check the time spent in the framework
33-
$this->assertLessThan(0.5, $profile->getCollector('timer')->getTime());
36+
$this->assertLessThan(
37+
0.5,
38+
$profile->getCollector('timer')->getTime()
39+
);
3440
}
3541
}
3642
}
@@ -42,7 +48,10 @@ finish. It's easy to achieve if you embed the token in the error message::
4248
$this->assertLessThan(
4349
30,
4450
$profile->get('db')->getQueryCount(),
45-
sprintf('Checks that query count is less than 30 (token %s)', $profile->getToken())
51+
sprintf(
52+
'Checks that query count is less than 30 (token %s)',
53+
$profile->getToken()
54+
)
4655
);
4756

4857
.. caution::

0 commit comments

Comments
 (0)