Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyze phtml files #7

Open
alexdrupal opened this issue Dec 22, 2018 · 1 comment
Open

Analyze phtml files #7

alexdrupal opened this issue Dec 22, 2018 · 1 comment

Comments

@alexdrupal
Copy link

Hello

Thank you for this plugin. I would like to analyze the phtml files. How this can be achieved ?
Also it would be nice to look at your phpstan config for Magento 1

Thank you so much!

@elluminatte
Copy link
Collaborator

Hi

This is our config for Magento 1:

parameters:
	autoload_directories:
		- %rootDir%/../../../app/code
		- %rootDir%/../../../lib/Varien
		- %rootDir%/../../../lib/Zend
		- %rootDir%/../../../lib/Ebizmarts
	autoload_files:
		- %rootDir%/../../../app/Mage.class.php
		- %rootDir%/../../../lib/Mage/Archive.php
	bootstrap: %rootDir%/../../../app/Stan.bootstrap.php
	excludes_analyse:
		- %rootDir%/../../../app/code/*/*/*/data/*
		- %rootDir%/../../../app/code/*/*/*/sql/*
		- %rootDir%/../../../app/code/local/Magestore/*
		- %rootDir%/../../../app/code/local/AdjustWare/*
		- %rootDir%/../../../app/code/local/Aschroder/*
		- %rootDir%/../../../app/code/local/Biztech/*
		- %rootDir%/../../../app/code/community/Hic/*
	ignoreErrors:
		- '#Call to an undefined method [a-zA-Z0-9\\_]+::get[a-zA-Z0-9\\_]+\(\)#'
		- '#Call to an undefined method [a-zA-Z0-9\\_]+::set[a-zA-Z0-9\\_]+\(\)#'
		- '#Call to an undefined method [a-zA-Z0-9\\_]+::uns[a-zA-Z0-9\\_]+\(\)#'
		- '#Call to method Imagick::[a-zA-Z0-9\\_]++\(\) with incorrect case:#'
		- '#Call to an undefined method Mage_Core_Block_Abstract::#'
		- "#Casting to [a-zA-Z0-9\\_(\\[\\]\\)?]+ something that's already [a-zA-Z0-9\\_(\\[\\]\\)?]+.#"
		- "#Access to an undefined property Ebizmarts_MailChimp::\\$[a-zA-Z0-9\\_]+#"
includes:
	- ../../vendor/BudsiesApp/phpstan-magento/extension.neon

Please note that you may do not need some lines related with third-party extension.
Also you could see Stan.bootstrap.php within autoload section. It's here:

<?php
define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BP', dirname(dirname(__FILE__)));

$paths   = ['/usr/local/lib/php'];
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';

$appPath = implode(PS, $paths);
set_include_path($appPath);

include_once "Mage/Core/functions.php";
Varien_Autoload::register();

\Mage::app();

As you can see, we are to instantiate Magento application to make analysis work. Because helpers, models, etc. are being resolved during App life cycle. I believe that there is more accurate and correct way to do this, but we use this solution for a while.

About .phtml files: we do not analyse them. To my mind it's too difficult to implement - we should know the block who is responsible to render the template, so we are to resolve the specific theme, specific layout, etc. Do you think it's possible? It would be cool if you implemented this feature. Waiting for your PR lol.

Regards, Nikolay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants