From 97b2e56a15c952d63718668f5d54b6ceca23f51d Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:19:42 +0200 Subject: [PATCH 1/7] [CS][Library] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Mon, 9 Jul 2012 16:34:21 +0200 Subject: [PATCH 2/7] [CS][test] Remove @copyright & @license for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@copyright/d' $fl.old > $fl; rm -f $fl.old; done; for fl in $(find . -name "*.php"); do mv $fl $fl.old; sed '/@license/d' $fl.old > $fl; rm -f $fl.old; done; --- test/Css2XpathTest.php | 4 ---- test/NodeListTest.php | 4 ---- test/QueryTest.php | 4 ---- 3 files changed, 12 deletions(-) diff --git a/test/Css2XpathTest.php b/test/Css2XpathTest.php index c4b3ae4..bd4b3a2 100644 --- a/test/Css2XpathTest.php +++ b/test/Css2XpathTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Dom * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Dom; @@ -29,8 +27,6 @@ * @category Zend * @package Zend_Dom * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Dom */ class Css2XpathTest extends \PHPUnit_Framework_TestCase diff --git a/test/NodeListTest.php b/test/NodeListTest.php index 6712db6..2036b28 100644 --- a/test/NodeListTest.php +++ b/test/NodeListTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Dom * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Dom; @@ -27,8 +25,6 @@ * @category Zend * @package Zend_Dom * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Dom */ class NodeListTest extends \PHPUnit_Framework_TestCase diff --git a/test/QueryTest.php b/test/QueryTest.php index 9e78866..794f3a2 100644 --- a/test/QueryTest.php +++ b/test/QueryTest.php @@ -15,8 +15,6 @@ * @category Zend * @package Zend_Dojo * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace ZendTest\Dom; @@ -30,8 +28,6 @@ * @category Zend * @package Zend_Dom * @subpackage UnitTests - * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) - * @license http://framework.zend.com/license/new-bsd New BSD License * @group Zend_Dom */ class QueryTest extends \PHPUnit_Framework_TestCase From 21278347fdc7775ba990a28de0273bed9217de34 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Mon, 9 Jul 2012 16:41:27 +0200 Subject: [PATCH 3/7] [CS][Tests] Set File Header http://framework.zend.com/wiki/display/ZFDEV2/Coding+Standards#CodingStandards-Files The following script replaces the content between PHP open tag and namespace declaration. for COMPONENT in $(ls -d *) do for FILE in $(find $COMPONENT -name "*.php") do BLOCK="\/\*\*\n \* Zend Framework \(http:\/\/framework\.zend\.com\/\)\n \*\n \* \@link http:\/\/github\.com\/zendframework\/zf2 for the canonical source repository\n \* \@copyright Copyright \(c\) 2005-2012 Zend Technologies USA Inc\. \(http:\/\/www\.zend\.com\)\n \* \@license http:\/\/framework\.zend\.com\/license\/new-bsd New BSD License\n \* \@package Zend_$COMPONENT\n \*\/" perl -0777 -i -pe "s/(<\?php(\s*.*)*\nn)/ Date: Mon, 9 Jul 2012 16:46:59 -0500 Subject: [PATCH 4/7] [zen-49] Correct import statements across framework - Ran a script that would create multiple import statements out of multi-line import statements, and which would sort all import statements in alphabetic order. Script is at https://gist.github.com/3079222 and was run by dropping into the library/Zend folder and typing (in zsh) "for file in **/*.php;do php /path/to/replace-uses.php $file; done" --- src/NodeList.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NodeList.php b/src/NodeList.php index de9800f..77f4155 100644 --- a/src/NodeList.php +++ b/src/NodeList.php @@ -10,12 +10,12 @@ namespace Zend\Dom; -use Iterator; use Countable; use DOMDocument; +use DOMElement; use DOMNodeList; use DOMXPath; -use DOMElement; +use Iterator; /** * Nodelist for DOM XPath query From 2b3577eb49769752de563395f708f636395f7b51 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 11 Jul 2012 09:03:53 -0500 Subject: [PATCH 5/7] [zendframework/zf2#1791] Updated for CS - Removed underscore prefix from all protected members - Docblocks changed to do namespace/import resolution of classes --- src/Query.php | 70 +++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Query.php b/src/Query.php index bc17d9a..87e7dbe 100644 --- a/src/Query.php +++ b/src/Query.php @@ -32,37 +32,37 @@ class Query /** * @var string */ - protected $_document; + protected $document; /** * DOMDocument errors, if any * @var false|array */ - protected $_documentErrors = false; + protected $documentErrors = false; /** * Document type * @var string */ - protected $_docType; + protected $docType; /** * Document encoding * @var null|string */ - protected $_encoding; + protected $encoding; /** * XPath namespaces * @var array */ - protected $_xpathNamespaces = array(); + protected $xpathNamespaces = array(); /** * XPath PHP Functions * @var mixed */ - protected $_xpathPhpFunctions; + protected $xpathPhpFunctions; /** * Constructor @@ -80,11 +80,11 @@ public function __construct($document = null, $encoding = null) * Set document encoding * * @param string $encoding - * @return \Zend\Dom\Query + * @return Query */ public function setEncoding($encoding) { - $this->_encoding = (null === $encoding) ? null : (string) $encoding; + $this->encoding = (null === $encoding) ? null : (string) $encoding; return $this; } @@ -95,7 +95,7 @@ public function setEncoding($encoding) */ public function getEncoding() { - return $this->_encoding; + return $this->encoding; } /** @@ -103,7 +103,7 @@ public function getEncoding() * * @param string $document * @param null|string $encoding Document encoding - * @return \Zend\Dom\Query + * @return Query */ public function setDocument($document, $encoding = null) { @@ -113,7 +113,7 @@ public function setDocument($document, $encoding = null) // breaking XML declaration to make syntax highlighting work if ('<' . '?xml' == substr(trim($document), 0, 5)) { if (preg_match('/]*xmlns="([^"]+)"[^>]*>/i', $document, $matches)) { - $this->_xpathNamespaces[] = $matches[1]; + $this->xpathNamespaces[] = $matches[1]; return $this->setDocumentXhtml($document, $encoding); } return $this->setDocumentXml($document, $encoding); @@ -129,12 +129,12 @@ public function setDocument($document, $encoding = null) * * @param string $document * @param null|string $encoding Document encoding - * @return \Zend\Dom\Query + * @return Query */ public function setDocumentHtml($document, $encoding = null) { - $this->_document = (string) $document; - $this->_docType = self::DOC_HTML; + $this->document = (string) $document; + $this->docType = self::DOC_HTML; if (null !== $encoding) { $this->setEncoding($encoding); } @@ -146,12 +146,12 @@ public function setDocumentHtml($document, $encoding = null) * * @param string $document * @param null|string $encoding Document encoding - * @return \Zend\Dom\Query + * @return Query */ public function setDocumentXhtml($document, $encoding = null) { - $this->_document = (string) $document; - $this->_docType = self::DOC_XHTML; + $this->document = (string) $document; + $this->docType = self::DOC_XHTML; if (null !== $encoding) { $this->setEncoding($encoding); } @@ -163,12 +163,12 @@ public function setDocumentXhtml($document, $encoding = null) * * @param string $document * @param null|string $encoding Document encoding - * @return \Zend\Dom\Query + * @return Query */ public function setDocumentXml($document, $encoding = null) { - $this->_document = (string) $document; - $this->_docType = self::DOC_XML; + $this->document = (string) $document; + $this->docType = self::DOC_XML; if (null !== $encoding) { $this->setEncoding($encoding); } @@ -182,7 +182,7 @@ public function setDocumentXml($document, $encoding = null) */ public function getDocument() { - return $this->_document; + return $this->document; } /** @@ -192,7 +192,7 @@ public function getDocument() */ public function getDocumentType() { - return $this->_docType; + return $this->docType; } /** @@ -202,7 +202,7 @@ public function getDocumentType() */ public function getDocumentErrors() { - return $this->_documentErrors; + return $this->documentErrors; } /** @@ -252,7 +252,7 @@ public function queryXpath($xpathQuery, $query = null) } $errors = libxml_get_errors(); if (!empty($errors)) { - $this->_documentErrors = $errors; + $this->documentErrors = $errors; libxml_clear_errors(); } libxml_use_internal_errors(false); @@ -261,30 +261,30 @@ public function queryXpath($xpathQuery, $query = null) throw new Exception\RuntimeException(sprintf('Error parsing document (type == %s)', $type)); } - $nodeList = $this->_getNodeList($domDoc, $xpathQuery); + $nodeList = $this->getNodeList($domDoc, $xpathQuery); return new NodeList($query, $xpathQuery, $domDoc, $nodeList); } /** * Register XPath namespaces * - * @param array $xpathNamespaces - * @return void + * @param array $xpathNamespaces + * @return void */ public function registerXpathNamespaces($xpathNamespaces) { - $this->_xpathNamespaces = $xpathNamespaces; + $this->xpathNamespaces = $xpathNamespaces; } /** * Register PHP Functions to use in internal DOMXPath * - * @param mixed $restrict + * @param mixed $restrict * @return void */ public function registerXpathPhpFunctions($xpathPhpFunctions = true) { - $this->_xpathPhpFunctions = $xpathPhpFunctions; + $this->xpathPhpFunctions = $xpathPhpFunctions; } /** @@ -294,17 +294,17 @@ public function registerXpathPhpFunctions($xpathPhpFunctions = true) * @param string|array $xpathQuery * @return array */ - protected function _getNodeList($document, $xpathQuery) + protected function getNodeList($document, $xpathQuery) { $xpath = new DOMXPath($document); - foreach ($this->_xpathNamespaces as $prefix => $namespaceUri) { + foreach ($this->xpathNamespaces as $prefix => $namespaceUri) { $xpath->registerNamespace($prefix, $namespaceUri); } - if ($this->_xpathPhpFunctions) { + if ($this->xpathPhpFunctions) { $xpath->registerNamespace("php", "http://php.net/xpath"); - ($this->_xpathPhpFunctions === true) ? + ($this->xpathPhpFunctions === true) ? $xpath->registerPHPFunctions() - : $xpath->registerPHPFunctions($this->_xpathPhpFunctions); + : $xpath->registerPHPFunctions($this->xpathPhpFunctions); } $xpathQuery = (string) $xpathQuery; return $xpath->query($xpathQuery); From 74f8e99efbbe9893d39353d6edaa466bf9f28585 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Wed, 11 Jul 2012 22:20:59 +0200 Subject: [PATCH 6/7] Add blank lines around the use block --- test/QueryTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/QueryTest.php b/test/QueryTest.php index 19c8285..eb72f7c 100644 --- a/test/QueryTest.php +++ b/test/QueryTest.php @@ -9,6 +9,7 @@ */ namespace ZendTest\Dom; + use Zend\Dom\Query; use Zend\Dom\NodeList; use Zend\Dom\Exception\ExceptionInterface as DOMException; From 1fa890055664b04d804eca366a24f136e780447f Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 12 Jul 2012 21:11:36 +0200 Subject: [PATCH 7/7] [PSR-2] fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed Applied php-cs-fixer --fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed --- src/Css2Xpath.php | 8 ++++---- src/Query.php | 4 ++-- test/QueryTest.php | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Css2Xpath.php b/src/Css2Xpath.php index 861ef1f..edb6542 100644 --- a/src/Css2Xpath.php +++ b/src/Css2Xpath.php @@ -100,7 +100,7 @@ function ($matches) { $expression = preg_replace_callback( '|\[([a-z0-9_-]+)~=[\'"]([^\'"]+)[\'"]\]|i', function ($matches) { - return "[contains(concat(' ', normalize-space(@" . strtolower($matches[1]) . "), ' '), ' " + return "[contains(concat(' ', normalize-space(@" . strtolower($matches[1]) . "), ' '), ' " . $matches[2] . " ')]"; }, $expression @@ -110,7 +110,7 @@ function ($matches) { $expression = preg_replace_callback( '|\[([a-z0-9_-]+)\*=[\'"]([^\'"]+)[\'"]\]|i', function ($matches) { - return "[contains(@" . strtolower($matches[1]) . ", '" + return "[contains(@" . strtolower($matches[1]) . ", '" . $matches[2] . "')]"; }, $expression @@ -118,8 +118,8 @@ function ($matches) { // Classes $expression = preg_replace( - '|\.([a-z][a-z0-9_-]*)|i', - "[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]", + '|\.([a-z][a-z0-9_-]*)|i', + "[contains(concat(' ', normalize-space(@class), ' '), ' \$1 ')]", $expression ); diff --git a/src/Query.php b/src/Query.php index 87e7dbe..efb4d45 100644 --- a/src/Query.php +++ b/src/Query.php @@ -57,7 +57,7 @@ class Query * @var array */ protected $xpathNamespaces = array(); - + /** * XPath PHP Functions * @var mixed @@ -278,7 +278,7 @@ public function registerXpathNamespaces($xpathNamespaces) /** * Register PHP Functions to use in internal DOMXPath - * + * * @param mixed $restrict * @return void */ diff --git a/test/QueryTest.php b/test/QueryTest.php index eb72f7c..1900ce3 100644 --- a/test/QueryTest.php +++ b/test/QueryTest.php @@ -51,7 +51,7 @@ public function loadHtml() $this->query->setDocument($this->getHtml()); } - public function handleError($msg, $code = 0) + public function handleError($msg, $code = 0) { $this->error = $msg; } @@ -205,8 +205,8 @@ public function testXpathPhpFunctionsShouldBeEnableWithoutParameter() $this->loadHtml(); $this->query->registerXpathPhpFunctions(); $result = $this->query->queryXpath('//meta[php:functionString("strtolower", @http-equiv) = "content-type"]'); - $this->assertEquals('content-type', - strtolower($result->current()->getAttribute('http-equiv')), + $this->assertEquals('content-type', + strtolower($result->current()->getAttribute('http-equiv')), $result->getXpathQuery()); } @@ -235,7 +235,7 @@ public function testLoadingDocumentWithErrorsShouldNotRaisePhpErrors() $this->assertTrue(is_array($errors)); $this->assertTrue(0 < count($errors)); } - + /** * @group ZF-9765 */ @@ -272,7 +272,7 @@ public function testAllowsSpecifyingEncodingAtConstruction() $doc = new Query($this->getHtml(), 'iso-8859-1'); $this->assertEquals('iso-8859-1', $doc->getEncoding()); } - + /** * @group ZF-3938 */ @@ -281,7 +281,7 @@ public function testAllowsSpecifyingEncodingWhenSettingDocument() $this->query->setDocument($this->getHtml(), 'iso-8859-1'); $this->assertEquals('iso-8859-1', $this->query->getEncoding()); } - + /** * @group ZF-3938 */ @@ -295,7 +295,7 @@ public function testAllowsSpecifyingEncodingViaSetter() * @group ZF-3938 */ public function testSpecifyingEncodingSetsEncodingOnDomDocument() - { + { $this->query->setDocument($this->getHtml(), 'utf-8'); $test = $this->query->execute('.foo'); $this->assertInstanceof('\\Zend\\Dom\\NodeList', $test); @@ -327,7 +327,7 @@ public function testXhtmlDocumentWithXmlAndDoctypeDeclaration() { $xhtmlWithXmlDecl = << -