示例#1
0
 /**
  * Tests if methods are used with correct count of parameters
  *
  * @param string $file
  * @dataProvider phpFilesDataProvider
  */
 public function testGetChildHtml($file)
 {
     $result = Utility_Classes::getAllMatches(file_get_contents($file), "/(->getChildHtml\\([^,()]+, ?[^,()]+,)/i");
     $this->assertEmpty($result, "3rd parameter is not needed anymore for getChildHtml() in '{$file}': " . print_r($result, true));
     $result = Utility_Classes::getAllMatches(file_get_contents($file), "/(->getChildChildHtml\\([^,()]+, ?[^,()]+, ?[^,()]+,)/i");
     $this->assertEmpty($result, "4th parameter is not needed anymore for getChildChildHtml() in '{$file}': " . print_r($result, true));
 }
示例#2
0
    /**
     * Scan contents as PHP-code and find class name occurrences
     *
     * @param string $contents
     * @param array &$classes
     * @return array
     */
    public static function collectPhpCodeClasses($contents, &$classes = array())
    {
        Utility_Classes::getAllMatches($contents, '/
            # ::getModel ::getSingleton ::getResourceModel ::getResourceSingleton
            \\:\\:get(?:Resource)?(?:Model | Singleton)\\(\\s*[\'"]([^\'"]+)[\'"]\\s*[\\),]

            # addBlock createBlock getBlockClassName getBlockSingleton
            | (?:addBlock | createBlock | getBlockClassName | getBlockSingleton)\\(\\s*[\'"]([^\'"]+)[\'"]\\s*[\\),]

            # Mage::helper ->helper
            | (?:Mage\\:\\:|\\->)helper\\(\\s*[\'"]([^\'"]+)[\'"]\\s*\\)

            # various methods, first argument
            | \\->(?:initReport | setDataHelperName | setEntityModelClass | _?initLayoutMessages
                | setAttributeModel | setBackendModel | setFrontendModel | setSourceModel | setModel
            )\\(\\s*[\'"]([^\'"]+)[\'"]\\s*[\\),]

            # various methods, second argument
            | \\->add(?:ProductConfigurationHelper | OptionsRenderCfg)\\(.+,\\s*[\'"]([^\'"]+)[\'"]\\s*[\\),]

            # models in install or setup
            | [\'"](?:resource_model | attribute_model | entity_model | entity_attribute_collection
                | source | backend | frontend | input_renderer | frontend_input_renderer
            )[\'"]\\s*=>\\s*[\'"]([^\'"]+)[\'"]

            # misc
            | function\\s_getCollectionClass\\(\\)\\s+{\\s+return\\s+[\'"]([a-z\\d_\\/]+)[\'"]
            | (?:_parentResourceModelName | _checkoutType | _apiType)\\s*=\\s*\'([a-z\\d_\\/]+)\'
            | \'renderer\'\\s*=>\\s*\'([a-z\\d_\\/]+)\'
            | protected\\s+\\$_(?:form|info|backendForm|iframe)BlockType\\s*=\\s*[\'"]([^\'"]+)[\'"]

            /Uix', $classes);
        // check ->_init | parent::_init
        $skipForInit = implode('|', array('id', '[\\w\\d_]+_id', 'pk', 'code', 'status', 'serial_number', 'entity_pk_value', 'currency_code'));
        Utility_Classes::getAllMatches($contents, '/
            (?:parent\\:\\: | \\->)_init\\(\\s*[\'"]([^\'"]+)[\'"]\\s*\\)
            | (?:parent\\:\\: | \\->)_init\\(\\s*[\'"]([^\'"]+)[\'"]\\s*,\\s*[\'"]((?!(' . $skipForInit . '))[^\'"]+)[\'"]\\s*\\)
            /Uix', $classes);
        return $classes;
    }
示例#3
0
 /**
  * @return array
  */
 public function getChildBlockDataProvider()
 {
     $result = array();
     foreach (Utility_Files::init()->getPhpFiles(true, false, true, false) as $file) {
         $aliases = Utility_Classes::getAllMatches(file_get_contents($file), '/\\->getChildBlock\\(\'([^\']+)\'\\)/x');
         foreach ($aliases as $alias) {
             $result[$file] = array($alias);
         }
     }
     return $result;
 }
示例#4
0
 /**
  * Special case: collect resource helper references in PHP-code
  *
  * @param string $contents
  * @param array &$classes
  */
 protected function _collectResourceHelpersPhp($contents, &$classes)
 {
     $regex = '/(?:\\:\\:|\\->)getResourceHelper\\(\\s*\'([a-z\\d_]+)\'\\s*\\)/ix';
     $matches = Utility_Classes::getAllMatches($contents, $regex);
     foreach ($matches as $moduleName) {
         $classes[] = "{$moduleName}_Model_Resource_Helper_Mysql4";
     }
 }