How to attach a project without mixing class declarations in PhpStorm? - phpstorm

I like PhpStorm's ability to attach multiple projects to the current window:
I've noticed, however, that all classes declared in both projects are available in both projects, which can lead to duplicate declarations:
I understand how this can be useful at times, however I'd like to attach projects just to navigate easily between them (I prefer this to switching windows), while keeping them separate as if they were in separate windows.
Is this possible?

Currently IDE does not have "scoped indexing" that may be able to resolve this. Right now you would need to exclude such duplicate files or tell IDE to not to treat them as PHP so they do not get indexed as such.
Your current options:
Use Mark Directory As | Excluded via context menu in Project View panel (or manually via Settings (Preferences on macOS) | Directories) for a folder(s) from additional project.
Mark individual files as Plain Text via context menu in Project View panel. The downside: such "marking" is IDE-wide as far as I know, so the same file path will be excluded in another project as well.
Any other exclusion mechanic that is currently available (e.g. Settings (Preferences on macOS) | Editor | File Types | Ignore files and folders -- global as well and based on file name only and file will be completely ignored from all operations... so not really acceptable for your case).
Consider watching after https://youtrack.jetbrains.com/issue/WI-17646 (star/vote/comment) and related tickets to get notified on any progress.
If they are the same classes, have you thought about making a composer package for them? Would be easier to manage it all I think.

Related

How to include software in PhpStorm project

I have just started using PhpStorm. In my project I am receiving a lot of undefined variable errors because I am creating a plugin for vBulletin.
I was wondering is there a way to include the main software I am working with in my plugin development, to avoid getting undefined vars, and functions? Kind of how the WordPress plugin development works.
For example I have my projects folder: c://wamp/www/projects/projectname/ and I have vBulletin in c://wamp/www/vb3/
I want to be able to tell PhpStorm "hey the core scripts to this project are here".
As LazyOne said I was able to achieve this using include paths.
Include paths are used for holding third-party code that is used for completion and reference resolution in some functions/methods that use file paths as arguments, for example, require() or include().
Note that the files added via include paths are not meant to be edited within the scope of your project. If you have the existing code that you need to access and modify from within several projects, consider adding it via an additional content root.
Do one of the following:
To configure the include paths for the current project, in the
Settings/Preferences dialog Ctrl+Alt+S, click PHP under Languages &
Frameworks.
To configure the include paths that will be applied to all newly
created projects, use the default new project settings (File | New
Projects Settings | Settings for New Projects ).
On the PHP page that opens, configure the list of include paths on the Include path tab:
Use Add and Remove to add and remove paths.
Use Move up and Move down to reorder the items in the list.
Click the Sort Alphabetically button to sort the paths alphabetically in the ascending order.

PhpStorm: multiple projects with common core

Due to security reasons, I have to split one project to divisions (client, admin, ...), and deploy them to different web servers. These divisions have one common script base, but each division has its own functions. As an IDE I use PhpStorm.
The question: what is the best way to organize project's structure and settings, so the common core part will be visible for IDE indexing in all project's divisions, but at the same time, being maintained from a single project (perhaps, standalone)?
In Java you can do lib jar files for further linking in various projects.
But how it can be done in PHP?
There are multiple ways of how to reference extra PHP code in a project.
If you plan to actively edit such extra code in the same project (and want to see their TODOs, code inspection warnings, include references in code refactoring etc):
You can just add it as an additional Content Root: Settings/Preferences | Directories. Folder added this way will be treated as a part of the project itself and will be shown as a separate node in the Project View panel (just as the main code, which is a Content Root as well).
Or you can open 2nd project while 1st one is already opened and when asked, just chose "Attach":
It's not going to be full 2 projects in one frame, more like something in between attaching Content Root and having 2 projects opened in separate frames.
https://www.jetbrains.com/help/phpstorm/opening-multiple-projects.html
Simple symlink will also do the job (but you need to place it somewhere in a project, e.g. PROJECT_ROOT/libs/my_symlinked_code). You then will need to provide a path mapping for that folder for debugger (if you will debug it of course) as PHP/Xdebug works with "final/resolved path" while IDE works with the path as is.
If you do not need to actively edit that extra code in the same window (and ignore any TODOs, code inspection warnings and other inspection results etc):
Do it as a composer package then? Composer can use custom sources (e.g. GitHub repo or a folder on a local filesystem).
Just add the path to that folder as a "Include Path" at Settings/Preferences | Languages & Frameworks | PHP --> Include Path tab. Code referenced this way is meant for 3rd party libraries (the code that you just use but not edit, e.g. framework code, your send mail/ORM library etc). Composer packages will also be included here by default.
https://www.jetbrains.com/help/phpstorm/php.html#include-path-tab

PhpStorm searching in project tool window

I'm using PhpStorm 10.0.4
When I start typing characters in project tool window it searchs for files containing typed text.
Is it possible to change this behavior so only files that begins with typed text would be matched?
Is it possible to change this behavior so only files that begins with typed text would be matched?
AFAIK no. There are no GUI settings for this at all.
Plus, this Speed Search is used in many places/tool windows and search logic is the same.
P.S. If you need to search for files .. why not try more appropriate (in general sense) Navigate | File... instead?
Speed Search only finds items in already expanded nodes (as it's a basic search on already displayed text) .. but Navigate | File... will look for files everywhere in the project.
It's not possible directly but you can create and use a scope for that.
Open Settings and go the Appearance & Behaviour -> Scopes. Create a new scope, give it a name (let's say "My Files") and put file:*/c* in the Pattern edit box.
In the big list of files under the Pattern edit box you can preview its effects. The files that are included in the scope are colored in green, the directories that contain included files are colored in blue.
This simple pattern selects only the files whose name start with c, in all directories. You can use slightly more complex filters using wild cards, include or exclude entire directories etc. With a little practice you can create filters that match usual needs pretty well.
When you are pleased with the scope definition, close the Settings box and go back to the Project view. Click on the arrow next to Project and you'll get a list of views of the project files. All the scopes you created should be there. Select "My Files" and only the files (and directories) included in that scope will be displayed in the Project view.
It is not a dynamic filter, you have to work a little to set it up, but it is useful when you work on large projects, with thousands of files, and you need to hide the files not important for your task.

How to exclude files from a project in PhpStorm by pattern?

I'm using PhpStorm 10.0.1. I want to exclude files in directories that match a pattern. I want this exclusion to remove the excluded files from the set of files that PhpStorm uses when - for example - finding duplicate definitions of classes.
I've gotten part of the way through the solution, which involves Scopes:
Open a project in PhpStorm
Go to Settings (File -> Settings)
Navigate to Appearance & Behavior -> Scopes
Create a scope to exclude the appropriate file(s).
Click the + icon
Select either Local or Shared
Give the scope a name
Enter an appropriate pattern
For example, to exclude files in directories that match *-b0*, enter !file:*-b0*/*
Click Exclude Recursively
Verify in the tree view that the appropriate file(s) are excluded.
Click OK.
This is where I'm stuck. I can't find any reference anywhere in the UI to that named scope - except in the settings dialog where I created it.
The documentation is no help:
https://www.jetbrains.com/phpstorm/help/scopes.html - "Scopes" describes how to create scopes but not how to use them
https://www.jetbrains.com/phpstorm/help/configuring-scopes-and-file-colors.html - "Configuring Scopes and File Colors" describes how to color files in a scope differently but not how to apply them to a project
How do I apply that scope to the current project?
(It may be the case that scopes are applied automatically. In that case, the Scopes dialog and the rest of PhpStorm disagree on what is included and what excluded and I'll need to file a bug.)
Scopes can be used in Project tool window - click the Project popup in upper left corner and choose the desired scope. They can only be used for search filtering (in Edit/Find/Find in path dialog), in Inspections profiles, file watchers, etc.
But note that choosing your scope in Project window is just a view option, files excluded from scope are NOT excluded from project - they will still be indexed, used in completion/navigation, etc. If you like to exclude certain files/folders completely, so that they are not included in file index, you need adding them to 'Ignore files and folders' in Settings | Editor | File Types. Folders can also be excluded using Mark directory as/Excluded
I've never heard of the ability to apply a custom scope globally. I believe they can only be used to allow specific components of PhpStorm (like code inspections & find/replace) to operate on a subset of your project's files. Edit: This is not accurate; please see the comments below.
This hacky workaround might just do the trick, if the files you'd like to exclude from your project are never going to change:
(a) Using the pattern you've already identified, create a new custom scope that specifically includes the undesirable files.
(b) Perform a very broad search against that scope (Find in Path > Scope > Custom > Custom Scopes), so that every undesired file is matched. You could potentially search for the text <?php, or use a regular expression like .+
(c) Create a new Favorites list, and add all of the search results to that list.
(d) From the Favorites window, highlight all of the files. Right click them and choose "Mark as plain text". This will prevent PhpStorm from indexing them, so they'll no longer be considered by the IDE's static code analysis.

PhpStorm multiple project navigation, quick switch between projects

How can I open few projects in left work area in PhpStorm? I need to quick switch between projects.
If you want to open more than one project in this way (and by this I mean so they have their own different settings), then currently it is not possible.
http://youtrack.jetbrains.com/issue/WI-15187 -- vote/star/comment to get notified on progress.
If you need to include files from those projects for reference purposes (to see how you have done it there, to copy some code from there etc) -- you can include them under "External Libraries" -- Settings | PHP | Include paths. Files included this way are protected from modifications.
If you need to modify those files ... you can add them into actual project as Additional Content Root (Settings | Directories| Add Content Root) -- such folders will be treated as part of the actual project with no separate settings.
Other than that -- Alt + Tab (or whatever the shortcut is on your OS) to switch between different PhpStorm windows (each project is opened in separate window/frame).
This is a right on time answer.
It is possible to quick switch between project by adding a keyboard shortcut to the "manage project" menu.
To do just that, go to Settings > Keymap and search for "Manage Projects". Then add it the keyboard shortcut you desire and you're all set.
Hope this will help someone looking for an answer like I did.
As LazyOne said, you can add paths to your project from Setting | PHP | Include paths or from the useful keystroke F4.
But I'd like to also share how I organise my projects, I think when you create a project, you should not open a new window but instead open it in the same window.
This way you don't get confused between the different opened windows.
In settings you can assign a keystroke to Reopen recent projects. I then use ctrl + shift + R but it is up for you to chose the keystroke you like.
Hope this will help you as I struggled as well to find a way to manage all my current projects.