/** * Process one php file. * * @param String $filename * the file name */ private function _processFile($filename) { if ($this->debug) { echo "Processing File : " . $filename . PHP_EOL; } // Reset the tokenizer $this->tokenizer->reset(); // Reset the state of the attributes $this->_resetValues(); // Try to detect the type of file in a MVC framework if (stripos($filename, 'view') !== false || stripos($filename, 'layouts') !== false) { $this->_isView = true; } elseif (stripos($filename, 'model') !== false) { $this->_isModel = true; } elseif (stripos($filename, 'controller') !== false) { $this->_isController = true; } elseif (stripos($filename, 'class') !== false) { // simple simple data objects $this->_isClass = true; } // Store the file name $this->_currentFilename = $filename; // By defaut the package name is based on the file name $this->_packageName = $this->_extractPackageName($filename); // Tokenize the file $this->tokenizer->tokenize($filename); // Empty PHP file if ($this->tokenizer->getTokenNumber() == 0) { $this->_checkEmptyFile($filename); return; // end the scan } // Go to the first token $token = $this->tokenizer->getCurrentToken(); // File start $this->_processFileStart(); // Run through every token of the file while ($token !== false) { // Process the token $this->_processToken($token); $this->lineNumber = $token->line; // Go to the next token $token = $this->tokenizer->getNextToken(); } // Test the last token of the file if ($this->_isActive('noFileCloseTag')) { if ($this->tokenizer->checkPreviousToken(T_CLOSE_TAG)) { // Closing tag is not recommended since PHP 5.0 $this->_writeError('noFileCloseTag', $this->_getMessage('END_FILE_CLOSE_TAG')); } } // Inner HTML is OK for views but not for other classes (controllers, models, ...) if ($this->_isActive('noFileFinishHTML') && !$this->_isView) { if ($this->tokenizer->checkPreviousToken(T_INLINE_HTML)) { $this->_writeError('noFileFinishHTML', $this->_getMessage('END_FILE_INLINE_HTML')); } } // Check for unused private functions $this->_checkUnusedPrivateFunctions(); // Check for unused variables $this->_checkUnusedVariables(); if ($this->_ncssFileClasses > 0 || $this->_ncssFileInterfaces > 0) { // Test the file name, only if it contains a class or interface $this->_checkFileNaming(); } // Write the count of lines for this file if ($this->_lineCountReporter != null) { $this->_lineCountReporter->writeFileCount($this->_packageName, $this->_ncssFileClasses, $this->_ncssFileInterfaces, $this->_ncssFileFunctions, $this->_ncssFileLinesOfCode, $this->_ncssFilePhpdoc, $this->_ncssFileLinesPhpdoc, $this->_ncssFileSingleComment, $this->_ncssFileMultiComment); } // Reset the suppression warnings $this->_fileSuppressWarnings = array(); $this->_classSuppressWarnings = array(); $this->_interfaceSuppressWarnings = array(); }