FrancisChung

PHPStorm for ProcessWire Developers

Recommended Posts

PHPStorm for PW Devs

This thread is a place for ProcessWire developers who use PHPStorm to share their experience, tips, frustrations, solutions, code snippets and generally discuss all things PHPStorm.

From Wikipedia:

JetBrains PhpStorm is a commercial, cross-platform IDE for PHP[1] built on JetBrains' IntelliJ IDEA platform.

PhpStorm provides an editor for PHP, HTML and JavaScript with on-the-fly code analysis, error prevention and automated refactorings for PHP and JavaScript code

 

Thanks @kongondo for the Visual Studio Code post earlier.

  • Like 5

Share this post


Link to post
Share on other sites

Does anyone know if it's possible to do something to "tell" PhpStorm how PW uses a template file and what variables are in scope there? For the purposes of code completion and to avoid erroneous undeclared variable warnings.

Currently I manually list all API variables and variables declared in the auto-prepended _init.php inside a DocBlock at the top of every template file. This works but gets pretty tiresome, especially when you need to make a change globally.

What would be cool is if PhpStorm could "know" that all API variables are available in every template file and that _init.php is prepended and so all the variables declared there are in scope. Anyone know a way to achieve this?

BTW, for API variables the Functions API is a no-go for me because I dislike all the string concatenation that goes with it. 

  • Like 2

Share this post


Link to post
Share on other sites
Quote

Does anyone know if it's possible to do something to "tell" PhpStorm how PW uses a template file and what variables are in scope there?

+1 for that!

Still waiting for a ProcessWire Plugin for PhpStorm.

All those lints are horrible :o

Share this post


Link to post
Share on other sites
8 hours ago, maxf5 said:

Still waiting for a ProcessWire Plugin for PhpStorm.

VS Code is in need of one too. :-)

  • Like 2

Share this post


Link to post
Share on other sites

There is the .phpstorm.meta.php in the wire folder with a note from Ryan.

Who can bring it up to work? :rolleyes:

<?php 
/**
 * ProcessWire PhpStorm Meta
 *
 * This file is not a CODE, it makes no sense and won't run or validate
 * Its AST serves PhpStorm IDE as DATA source to make advanced type inference decisions.
 *
 * @see https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata
 */


	$STATIC_METHOD_TYPES = [
		\wire('') => [
			'' == '@',
			'config' instanceof \ProcessWire\Config,
			'cache' instanceof \ProcessWire\WireCache,
			'wire' instanceof \ProcessWire\ProcessWire,
			'log' instanceof \ProcessWire\WireLog,
			'notices' instanceof \ProcessWire\Notices,
			'sanitizer' instanceof \ProcessWire\Sanitizer,
			'database' instanceof \ProcessWire\WireDatabasePDO,
			'db' instanceof \ProcessWire\DatabaseMysqli,
			'cache' instanceof \ProcessWire\MarkupCache,
			'modules' instanceof \ProcessWire\Modules,
			'procache' instanceof \ProCache,
			'fieldtypes' instanceof \ProcessWire\Fieldtypes,
			'fields' instanceof \ProcessWire\Fields,
			'fieldgroups' instanceof \ProcessWire\Fieldgroups,
			'templates' instanceof \ProcessWire\Templates,
			'pages' instanceof \ProcessWire\Pages,
			'permissions' instanceof \ProcessWire\Permissions,
			'roles' instanceof \ProcessWire\Roles,
			'users' instanceof \ProcessWire\Users,
			'user' instanceof \ProcessWire\User,
			'session' instanceof \ProcessWire\Session,
			'input' instanceof \ProcessWire\WireInput,
			'languages' instanceof \ProcessWire\Languages,
			'page' instanceof \ProcessWire\Page,
			'hooks' instanceof \ProcessWire\WireHooks,
			'files' instanceof \ProcessWire\WireFileTools,
			'datetime' instanceof \ProcessWire\WireDateTime,
			'mail' instanceof \ProcessWire\WireMailTools
		],
		\Wire::wire('') => [
			// this one does not appear to work, leaving in case someone knows how to make it work
			'' == '@',
			'config' instanceof \ProcessWire\Config,
			'cache' instanceof \ProcessWire\WireCache,
			'wire' instanceof \ProcessWire\ProcessWire,
			'log' instanceof \ProcessWire\WireLog,
			'notices' instanceof \ProcessWire\Notices,
			'sanitizer' instanceof \ProcessWire\Sanitizer,
			'database' instanceof \ProcessWire\WireDatabasePDO,
			'db' instanceof \ProcessWire\DatabaseMysqli,
			'cache' instanceof \ProcessWire\MarkupCache,
			'modules' instanceof \ProcessWire\Modules,
			'procache' instanceof \ProCache,
			'fieldtypes' instanceof \ProcessWire\Fieldtypes,
			'fields' instanceof \ProcessWire\Fields,
			'fieldgroups' instanceof \ProcessWire\Fieldgroups,
			'templates' instanceof \ProcessWire\Templates,
			'pages' instanceof \ProcessWire\Pages,
			'permissions' instanceof \ProcessWire\Permissions,
			'roles' instanceof \ProcessWire\Roles,
			'users' instanceof \ProcessWire\Users,
			'user' instanceof \ProcessWire\User,
			'session' instanceof \ProcessWire\Session,
			'input' instanceof \ProcessWire\WireInput,
			'languages' instanceof \ProcessWire\Languages,
			'page' instanceof \ProcessWire\Page,
			'hooks' instanceof \ProcessWire\WireHooks,
			'files' instanceof \ProcessWire\WireFileTools,
			'datetime' instanceof \ProcessWire\WireDateTime,
			'mail' instanceof \ProcessWire\WireMailTools
		],
	];

 

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kongondo
      Visual Studio Code for PW Devs
      This thread is a place for ProcessWire developers who use Visual Studio Code (aka VSC or Code)  to share their experience, tips, frustrations , solutions, code snippets and generally discuss all things VSC.
      From Wikipedia:
       
    • By szabesz
      CodeRunner 2 is on sale at MacUpdate: https://www.macupdate.com/app/mac/38362/coderunner
      Mostly I use it for writing shell scripts, mocking up algorithms in PHP, JavaScript/jQuery. But is also supports other programming languages as well.
      https://coderunnerapp.com/
      "An advanced, highly flexible, and easy-to-use programming editor for your Mac. CodeRunner supports a large number of languages, and delivers big IDE features while remaining lightweight and clutter-free."
    • By pwFoo
      I moved from netbeans to atom. Tested lighttable, brackets and visual studio code, but at the moment I take a look into web based IDEs. Most are based on ACE editor (alternative could be codemirror) like chrome apps caret or super neutron drive (both with chrome dependency at the moment). 
      Recently I looked into cloud9, codetasty, ... and codiad.
      Codiad is open source. php / js based and works fine. Autocomplete feature and suggestions should be improved, but it's ok. Because it's open source you can download it from github repo or test it as a docker container (wernight/codiad image for example). 
      Codytasty is a cloud hosted solution with a really awesome autocomplete / suggestions for php, js and html! But it isn't open source (there is a free to use hosted version with limited workspaces and features).
      At the moment I testing codiad@docker, but use still atom for coding and searching for the best IDE out there *g*
       
      What do you think about IDEs and the new trend to web based IDEs?
    • By FrancisChung
      I'm writing this to give back something to the community that has given so much up front over the past year.
      I noticed there's hardly any discussion about testing in these forums so I decided to write this quick primer to get some discussion going.
      I'm by no means an expert on phpunit or selenium but I had to jump through a few hoops to get it working (especially with PHPStorm), so I thought I figured I should share my experiences with the community. 

      Also, I'm hoping non Phpstorm users can still  pick something up useful in this post.

      Prerequisites : It is assumed Phpunit (https://phpunit.de/) is installed via Composer,   Selenium (http://www.seleniumhq.org/) and Php-webdriver for Selenium (https://github.com/facebook/php-webdriver) is preinstalled.
      For Phpstorm users, there's a fairly detailed installation and unit testing instructions here (https://www.jetbrains.com/help/phpstorm/2016.1/testing.html)
      I found some parts of it leaving me with unanswered questions, so I'm hoping this post will supplement any questions that you might encounter.

      Rather than writing a single monolithic post, I will write several posts covering different topics.