Преглед изворни кода

Fixes CS in Zend_Pdf and Zend_PdfTest

Frank Brückner пре 11 година
родитељ
комит
b0e8a4d02b
2 измењених фајлова са 67 додато и 34 уклоњено
  1. 52 24
      library/Zend/Pdf.php
  2. 15 10
      tests/Zend/PdfTest.php

+ 52 - 24
library/Zend/Pdf.php

@@ -206,7 +206,6 @@ class Zend_Pdf
      */
     protected $_parser;
 
-
     /**
      * List of inheritable attributesfor pages tree
      *
@@ -220,7 +219,7 @@ class Zend_Pdf
      * @var array - Associative array, key: name of form field, value: Zend_Pdf_Element
      */
     protected $_formFields = array();
-	
+
     /**
      * True if the object is a newly created PDF document (affects save() method behavior)
      * False otherwise
@@ -616,6 +615,7 @@ class Zend_Pdf
   
     /**
      * Load form fields
+     *
      * Populates the _formFields array, for later lookup of fields by name
      *
      * @param Zend_Pdf_Element_Reference $root Document catalog entry
@@ -625,24 +625,28 @@ class Zend_Pdf
         if ($root->AcroForm === null || $root->AcroForm->Fields === null) {
             return;
         }
-        
-        foreach ($root->AcroForm->Fields->items as $field)
-        {
+
+        foreach ($root->AcroForm->Fields->items as $field) {
             /* We only support fields that are textfields and have a name */
-            if ( $field->FT && $field->FT->value == 'Tx' && $field->T && $field->T !== null ) 
-            {
+            if ($field->FT && $field->FT->value == 'Tx' && $field->T
+                && $field->T !== null
+            ) {
                 $this->_formFields[$field->T->value] = $field;
             }
         }
-		
-        if ( !$root->AcroForm->NeedAppearances || !$root->AcroForm->NeedAppearances->value )
-        {
+
+        if (!$root->AcroForm->NeedAppearances
+            || !$root->AcroForm->NeedAppearances->value
+        ) {
             /* Ask the .pdf viewer to generate its own appearance data, so we do not have to */
-            $root->AcroForm->add(new Zend_Pdf_Element_Name('NeedAppearances'), new Zend_Pdf_Element_Boolean(true) );
+            $root->AcroForm->add(
+                new Zend_Pdf_Element_Name('NeedAppearances'),
+                new Zend_Pdf_Element_Boolean(true)
+            );
             $root->AcroForm->touch();
-        }    
+        }
     }
-	
+
     /**
      * Retrieves a list with the names of the AcroForm textfields in the PDF
      *
@@ -652,7 +656,7 @@ class Zend_Pdf
     {
         return array_keys($this->_formFields);
     }
-	
+
     /**
      * Sets the value of an AcroForm text field
      *
@@ -662,24 +666,48 @@ class Zend_Pdf
      */
     public function setTextField($name, $value)
     {
-        if ( !isset($this->_formFields[$name]))
-            throw new Zend_Pdf_Exception("Field '$name' does not exist or is not a textfield");
-		
+        if (!isset($this->_formFields[$name])) {
+            throw new Zend_Pdf_Exception(
+                "Field '$name' does not exist or is not a textfield"
+            );
+        }
+
+        /** @var Zend_Pdf_Element $field */
         $field = $this->_formFields[$name];
-        $field->add(new Zend_Pdf_Element_Name('V'), new Zend_Pdf_Element_String($value) );
-        $field->touch();      
+        $field->add(
+            new Zend_Pdf_Element_Name('V'), new Zend_Pdf_Element_String($value)
+        );
+        $field->touch();
     }
-    
+
+    /**
+     * Sets the properties for an AcroForm text field
+     *
+     * @param string $name
+     * @param mixed  $bitmask
+     * @throws Zend_Pdf_Exception
+     */
     public function setTextFieldProperties($name, $bitmask)
     {
-        if ( !isset($this->_formFields[$name]))
-            throw new Zend_Pdf_Exception("Field '$name' does not exist or is not a textfield");
+        if (!isset($this->_formFields[$name])) {
+            throw new Zend_Pdf_Exception(
+                "Field '$name' does not exist or is not a textfield"
+            );
+        }
 
         $field = $this->_formFields[$name];
-        $field->add(new Zend_Pdf_Element_Name('Ff'), new Zend_Pdf_Element_Numeric($bitmask));
+        $field->add(
+            new Zend_Pdf_Element_Name('Ff'),
+            new Zend_Pdf_Element_Numeric($bitmask)
+        );
         $field->touch();
     }
-    
+
+    /**
+     * Marks an AcroForm text field as read only
+     *
+     * @param string $name
+     */
     public function markTextFieldAsReadOnly($name)
     {
         $this->setTextFieldProperties($name, self::PDF_FORM_FIELD_READONLY);

+ 15 - 10
tests/Zend/PdfTest.php

@@ -40,28 +40,31 @@ require_once 'Zend/Pdf/Exception.php';
 class Zend_PdfTest extends PHPUnit_Framework_TestCase
 {
     /**
-     *
-     * @var NULL|Zend_Pdf
+     * @var Zend_Pdf = null
      */
-    private $_pdf = NULL;
+    private $_pdf;
 
     protected function setUp()
     {
         $this->_pdf = Zend_Pdf::load(dirname(__FILE__) . '/Pdf/_files/PdfWithFields.pdf');
     }
 
+    /**
+     * PDF with text fields must return array of text field names
+     */
     public function testGetTextFieldNames()
     {
         $fieldNames = $this->_pdf->getTextFieldNames();
-        //PDF with text fields must return array of text field names
         $this->assertEquals(array('Field1', 'Field2'), $fieldNames);
     }
 
+    /**
+     * PDF with no text fields must return empty array
+     */
     public function testGetTextFieldNamesNoFieldsEmptyArray()
     {
-        $pdf = new Zend_Pdf();
+        $pdf        = new Zend_Pdf();
         $fieldNames = $pdf->getTextFieldNames();
-        //PDF with no text fields must return empty array
         $this->assertEquals(array(), $fieldNames);
     }
 
@@ -69,7 +72,7 @@ class Zend_PdfTest extends PHPUnit_Framework_TestCase
     {
         try {
             $this->_pdf->setTextField('Field1', 'Value1');
-            $this->assertTrue(TRUE);    //in case of --strict
+            $this->assertTrue(true); // in case of --strict
         } catch (\Exception $e) {
             $this->fail('Failed to set an existing text field');
         }
@@ -104,7 +107,7 @@ class Zend_PdfTest extends PHPUnit_Framework_TestCase
                     | Zend_Pdf::PDF_FORM_FIELD_REQUIRED
                     | Zend_Pdf::PDF_FORM_FIELD_NOEXPORT
             );
-            $this->assertTrue(TRUE);    //in case of --strict
+            $this->assertTrue(true); // in case of --strict
         } catch (\Exception $e) {
             $this->fail('Failed to set property of an existing text field');
         }
@@ -119,7 +122,9 @@ class Zend_PdfTest extends PHPUnit_Framework_TestCase
      */
     public function testSetTextFieldPropertiesNonExistent()
     {
-        $this->_pdf->setTextFieldProperties('FieldNotExists', Zend_Pdf::PDF_FORM_FIELD_REQUIRED);
+        $this->_pdf->setTextFieldProperties(
+            'FieldNotExists', Zend_Pdf::PDF_FORM_FIELD_REQUIRED
+        );
     }
 
     public function testMarkTextFieldAsReadOnly()
@@ -127,7 +132,7 @@ class Zend_PdfTest extends PHPUnit_Framework_TestCase
         try {
             $this->_pdf->markTextFieldAsReadOnly('Field1');
             $this->_pdf->markTextFieldAsReadOnly('Field2');
-            $this->assertTrue(TRUE);    //in case of --strict
+            $this->assertTrue(true); // in case of --strict
         } catch (\Exception $e) {
             $this->fail('Failed to set an existing text field as read-only');
         }