Skip to content

Instantly share code, notes, and snippets.

@totten
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totten/8f0881bfdcd00901c826 to your computer and use it in GitHub Desktop.
Save totten/8f0881bfdcd00901c826 to your computer and use it in GitHub Desktop.
coder: Multi-line string in array
<?php
/**
* @file
*
* Example where an array() contains a multi-line string.
*
* The problem here is that there seems to be no good way to include
* a multi-line string in an array. The options are either to put the
* entire string on oneline (which makes it illegible) or (in theory)
* to inject whitespace into the string (which changes the content).
*/
// This complains about indentation.
$this->xmlExamples['a'] = array(
'name' => 'example_a',
'title' => 'Example A',
'xml' => '
<foo>
<bar>
123456789 123456789 123456789 123456789 123456789 123456789 123456789
123456789 123456789 123456789 123456789 123456789 123456789 123456789
</bar>
</foo>',
);
// This complains about unnecessary concatenation.
//
// Note that several lines are individually <80char but that combining them
// all would make an absurdly long string.
//
// Also: Feels like each piecemeal string should be indented.
$this->xmlExamples['b'] = array(
'name' => 'example_b',
'title' => 'Example B',
'xml' => ""
. "<foo>\n"
. " <bar>\n"
. " 123456789 123456789 123456789 123456789 123456789 123456789 123456789\n"
. " 123456789 123456789 123456789 123456789 123456789 123456789 123456789\n"
. " </bar>\n"
. "</foo>\n",
);
// @codingStandardsIgnoreStart
// CURRENT OUTPUT (circa 1b8024a0c18255e7dc0a6b3ab8a8ee4cc721ba79)
// --------------------------------------------------------------------------------
// FOUND 9 ERRORS AFFECTING 9 LINES
// --------------------------------------------------------------------------------
// 18 | ERROR | [x] Array indentation error, expected 2 spaces but found 0
// 19 | ERROR | [x] Array indentation error, expected 2 spaces but found 0
// 20 | ERROR | [x] Array indentation error, expected 2 spaces but found 0
// 21 | ERROR | [x] Array indentation error, expected 2 spaces but found 0
// 22 | ERROR | [x] Array indentation error, expected 2 spaces but found 0
// 23 | ERROR | [x] Array indentation error, expected 2 spaces but found 0
// 36 | ERROR | [ ] String concat is not required here; use a single string
// | | instead
// 37 | ERROR | [ ] String concat is not required here; use a single string
// | | instead
// 41 | ERROR | [ ] String concat is not required here; use a single string
// | | instead
// --------------------------------------------------------------------------------
// PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
// --------------------------------------------------------------------------------
// @codingStandardsIgnoreEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment