It is just one of the files. I have also tried to write some tests using PHPUnit. Please give me some suggestions to improve my coding-writing skills.The below is the test file for the above file:<?phpclass TestParseXML extends PHPUnit_Framework_TestCase{       public function testSetup()        {            $objectParseXML = new ParseXML(test.txt);            return $objectParseXML;        }       /**        * @depends testSetup        */       public function testParseObject($objectParseXML)            {               $objectParseXML->current_line = <Article>;                return $objectParseXML->current_line;              }        /**         * @depends testSetup         * @depends testParseObject         */        public function testtagNameOn($objectParseXML, $currentLine){            $this->assertEmpty($objectParseXML->tree);            $objectParseXML->scanCharacter('<', 0);            $this->assertTrue($objectParseXML->isTagName);        }        /**         * @depends testSetup         * @depends testParseObject         */        public function testTagContentOn($objectParseXML){            $objectParseXML->isTagName = True;            $objectParseXML->scanCharacter('>', 3);            $this->assertTrue($objectParseXML->isTagContent);            $this->assertNotTrue($objectParseXML->isTagName);        }}?>Code Files:<?phprequire('XML.php');class OpenXML extends XML{    var $fileHandler;    public function openXMLFile($filename, $mode='r'){        $this->fileHandler = @fopen($filename, $mode);    }    public function getHandler()    {        return $this->fileHandler;    }    public function getHandlerType(){       return get_resource_type($this->fileHandler);    }}?><?phprequire('ReadXML.php');class ParseXML extends ReadXML{    public $handle;    public $current_line;    public $isTagName = False;    public $isTagContent = False;    public $startParse = False;    public $tagName;    public $tagContent;    public $tree = array();//Call appropriate function depend on $isTagName and $isTagContent    public function scanCharacter($char, $index)    {               if(strcmp($char, '<')==0)               {                  if($this->isTagContent){                        $this->isTagContent = False;                  }                  if($index+1 < $this->getLen())                  {                      $this->isTagName = $this->tagNameOn($this->current_line[$index+1]);                    }               }               elseif($this->isTagName and (strcmp($char, '>')==0))               {                  $this->isTagName = $this->tagNameOff();                    $this->isTagContent = $this->tagContentOn();               }               elseif((strcmp($char, '/')==0)){                        $this->isTagName = False;                        $this->isTagContent = False;               }                               elseif($this->isTagName and !strcmp($char, ' '))               {                  $this->isTagName = $this->tagNameOff();                 }               elseif($this->isTagName)               {                    $this->gatherTagName($char);               }               elseif($this->startParse and $this->isTagContent)               {                    $this->gatherTagContent($char);               }    }    public function tagNameOn($nextChar)    {        if(!strcmp($nextChar, '/')==0)           {               $this->tagName = ;               return True;           }//        print_r($this->tagName);//        print_r(\n);//        print_r($this->tagContent);        $this->isTagContent = False;        return False;    }    public function tagNameOff()    {            if(!($this->startParse) and strcmp($this->tagName, 'Document') == 0){                    $this->startParse = True;                }            return False;    }    public function getLen(){        return strlen($this->current_line);    }    public function tagContentOn()    {        return True;    }    public function gatherTagName($char){         $this->tagName.= $char;    }    public function gatherTagContent($char){         $this->tagContent.= $char;    }    public function getTag()    {           $this->tagContent = trim($this->tagContent);           if($this->tagName and $this->tagContent){             if(!$this->isTagContent){                array_push($this->tree, array($this->tagName, $this->tagContent));                $this->tagContent = ;                $this->tagName = ;            }        }    }    public function getTagContent(){        $listNames = array();        forEach($this->tree as $value){            array_push($listNames, $value[1]);        }        return $listNames;    }    public function getTagNames(){        $listNames = array();        forEach($this->tree as $value){            array_push($listNames, $value[0]);        }        return $listNames;    }    public function readLine()    {          $this->handle = $this->getHandle();           $this->current_line = fgets($this->handle);           while($this->current_line)          {              for ($i = 0; $i < $this->getLen(); $i++)                {                   $char = $this->current_line[$i];                    $this->scanCharacter($char, $i);                }               $this->getTag();             }          return $this->tree;    }    public function goOverLine(){    }}$a = new ParseXML('../IMQ+AZIBPrototyp.xml');$a->openXMLFile($a->getFileName());$a->acquireHandler();$a->readLine();print_r($a->getTagContent());?>ReadXML.php<?phprequire('OpenXML.php');class ReadXML extends OpenXML{    var $content;    var $line;    public function acquireHandler()    {        $this->content = $this->getHandler();    }    public function getHandle()    {        return $this->content;    }    public function isReadLine()    {        return feof($this->content);    }     public function getLine()    {        if(!($this->isReadLine()))        {            $this->line = fgets($this->content);            return $this->line;        }    }}?>
XML parser using PHP
php;parsing;xml;phpunit
Good to see you are using PHPUnit as testing method :)Issuelist:Curly brackets are sometimes in same line as a method header and sometimes in the followingThere are both empty methods and methods that return always true/falseNot every method has a self-describing nameThere are global attributes with the access modifier publicThere are multiple returns in one methodClasses are included manuallyPHP-tags are closedRecommendationCurly brackets are sometimes in same line as a method header and sometimes in the followingFor the sake of a good code-reading and understanding code should be structured. Write curly brackets either in the same line as the method header or in the following.There are both empty methods and methods that return always trueParseXML::goOverLine(): When a method body is empty it usually means you have not implemented its logic yet. It is possible that one forget to include its logic but calls the method which can leads to a difficult to identify bug at a later time. Therefor I recommend to throw an Exception with message Method not implemented.ParseXML::tagContentOn(), ParseXML::tagNameOff(): Why does this method returns true/false anytime? Does it switches tags on/off?ParseXML::gatherTagName($char), ParseXML::gatherTagContent($char): These methods rather append, do they? Or does this word describes appending as well?Not every method has a self-describing nameParseXML::getLen(): What does it return? Object Length, Current Line Length, ...? I recommend to rename the method to what it does - getCurrentLineLength().There are global attributes with the access modifier publicAn object is responsible for its valditity. As of that its attributes has to be setted via setters always and the attributes has to have as access modifier either protected or private.There are multiple returns in one methodThis makes the code less maintainable. Having more than one return means there are multiple scenarios when the method can be stopped. In case of a bug one need to debug through the whole method to figure out the return-point.Classes are included manuallyInstead of including classes manually it is recommended to make usage of the autoloader function (http://php.net/manual/en/function.spl-autoload-register.php). The advantage is that you don't have to worry about including a class.PHP-tags are closedIt is not recommend to close the PHP-tag. It can happen that you have an empty space after the closed PHP-tag which leads to headers already sent error. Not closing them reduces headaches :)