Skip to content

Instantly share code, notes, and snippets.

@natanfelles
Last active January 25, 2024 03:48
Show Gist options
  • Save natanfelles/a909a82936410c8ddcd917b8528faeeb to your computer and use it in GitHub Desktop.
Save natanfelles/a909a82936410c8ddcd917b8528faeeb to your computer and use it in GitHub Desktop.
Atom PHP Environment + CodeIgniter 3 & 4

Atom PHP Environment + CodeIgniter 3 & 4

Atom Editor

Install

Download and install Atom Editor:

cd ~/Downloads
wget https://github.com/atom/atom/releases/download/v1.15.0/atom-amd64.deb
sudo dpkg -i atom-amd64.deb

Install required SO packages:

sudo apt install php php-sqlite3 php-mbstring sqlite3 composer npm

Code Formatters

atom-beautify uses JS Beautify by default.

sudo npm -g install js-beautify
apm install atom-beautify

For PHP, atom-beautify follow coding standards from php-codesniffer.

Install php-codesniffer:

sudo apt install php-codesniffer

After, you can see the default Standards with the command phpcs -i. The output will be like:

The installed coding standards are PEAR, Squiz, MySource, PHPCS, Zend, PSR1 and PSR2

CodeIgniter has your own Codeing Standard and the CodeIgniter-for-PHP_CodeSniffer follow this rules.

We can install the CodeIgniter Standard as follow:

mkdir CodeIgniter-for-PHP_CodeSniffer
cd CodeIgniter-for-PHP_CodeSniffer
wget https://github.com/thomas-ernest/CodeIgniter-for-PHP_CodeSniffer/archive/master.zip
unzip master.php

Now, lets put the src folder in the correct path:

sudo cp -r CodeIgniter-for-PHP_CodeSniffer-master/src/ /usr/share/php/PHP/CodeSniffer/Standards/CodeIgniter/

Now, the output of phpcs -i will be:

The installed coding standards are PEAR, Squiz, MySource, PHPCS, Zend, PSR1, PSR2 and CodeIgniter

If do you wnat, you can change the PHPCBF Standard to CodeIgniter.

TODO: Is possible setup PHPCBF Standard by project-manager file?

Linters

sudo npm -g install linter
sudo npm -g install htmlhint
sudo npm -g install csslint
sudo npm -g install jshint

apm install linter
apm install linter-htmlhint
apm install linter-csslint
apm install linter-jshint

The Awesome

PHP Integrator is a powerfull project that provides code analysis and utilities for PHP projects.

PHP Integrator uses composer to install the core and you need install the correct version corresponding to the php-integrator-base version.

composer global require php-integrator/core 2.1.1

PHP Integrator uses the project-manager to activate resources based by project.

Lets install the Atom packages:

apm install project-manager
apm install php-integrator-base
apm install php-integrator-linter
apm install php-integrator-annotations
apm install php-integrator-autocomplete-plus
apm install php-integrator-call-tips
apm install php-integrator-navigation
apm install php-integrator-tooltips
apm install php-integrator-refactoring

CodeIgniter

Atom CodeIgniter

When you works on a CodeIgniter 3 project you can download this file https://raw.githubusercontent.com/natanfelles/codeigniter-phpstorm/master/phpstorm.php inside your project root.

After go to Atom and open the menu Packages > Project Manager > Edit Projects and configure your project like it:

{
  title: "CodeIgniter 3"
  paths: [
    "/home/username/codeigniter3"
  ]
  icon: "icon-flame"
  devMode: false
  php:
    enabled: true
    php_integrator:
      enabled: true
      phpVersion: 5.6
      excludedPaths: [
          "{0}/application/cache/",
          "{0}/application/logs/",
          "{0}/system/core/Controller.php",
          "{0}/system/core/Model.php"
      ]
      fileExtensions: [
        "php"
      ]
}

This tip will do PHP Integrator do not read the Controller.php and Model.php from the system folder, then it will use all the @property from phpstorm.php file.

You can read more about it in Code Completion for CodeIgniter in phpStorm and here Excluding Folders From Indexing.

On CodeIgniter 4 you do not need do this config. PHP Integrator will works natively well.

Extras

Some extra packages that I like:

apm install atom-ternjs
apm install color-picker
apm install pigments
apm install git-plus
apm install docblockr
apm install bootstrap3-snippets
apm install file-icons
apm install editorconfig
apm install todo-show
apm install highlight-selected
apm install emmet
apm install minimap
apm install language-htaccess
apm install language-markdown
apm install linter-write-good
apm install linter-json-lint
apm install api-docs
apm install sync-settings
@fernandomuslimin
Copy link

where to put the phpstorm.php file? i put in at the same directory with index.php, and config the projects. but it wont show me any autocompletes like on pict above.

can you tell me little bit detail about this?
[ { title: "CIS" paths: [ "C:\\xampp\\htdocs\\CIS" ] icon: "icon-flame" php: enabled: true php_integrator: enabled: true phpVersion: 7.1 excludedPaths: [ "{0}/application/cache/" "{0}/application/logs/" "{0}/system/core/Controller.php" "{0}/system/core/Model.php" ] fileExtensions: [ "php" ] } ]

that is my project configuration

@natanfelles
Copy link
Author

First you need know if php-integrator is really working. Create a test project with a simple class and try extends it. If auto complete do not works then the issue is on the installation, check the instructions on php-integrator site.

The phpstorm.php file can be in your project root or inside application folder.

I never used this on Windows OS. Is correct the path have two backslashes \\ and not one?

And try to reindex your project if changed the projects.cson file. Menu Packages > PHP Integrator > Forcibly (Re)index Project.

Good look. If you solve this, please comment what to do for others.

@vanthao03596
Copy link

Please tell me how to fix this error
screenshot from 2018-03-11 17-37-16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment