In PhpStorm, can I create a new "module" (i.e. handful of files at the same time) - phpstorm

I would like to be able to right click in a folder in PhpStorm, and select something like, "New Custom Module", which will then create directories and files as per a definition that I set up somewhere.
Is this possible at all?
Detailed description of what I would do:
In the "Edit File Templates" window (or something similar), I would add a new entry, calling it "New Custom Module". I would then +/- directories and file types that I would like to be created when I select to create that module.
For example, I could set up the "New Custom Module" to create a Controllers directory with a controller class inside it, a Model directory with a model class inside it, a composer.json file and a registration.php file. So when selecting this menu option from right clicking on a directory in the Project panel, I would get the following:
[top-level-directory]
- Controllers
- People.php
- Models
- Person.php
- composer.json
- registration.php
Ideally I could also select what the starting contents of the files would be, but if I can just create blank file/directories for now, that would be pretty great

Closest you can get is a "Project template" (saving project as a template). But unfortunately there's nothing similar to what you're requesting.
There's an existing feature request for this: https://youtrack.jetbrains.com/issue/IDEA-91565. Feel free to vote/comment.

Related

PhpStorm using incorrect namespaces

I have an issue with my PhpStorm using incorrect namespaces when creating a new class.
Example:
I have a module named Booking. Inside Booking I want to create a controller called StatusController. The directory the controller class will be created in is Booking/src/Controller, and after being created it's namespace should be Booking\Controller, but my IDE is making it Booking\src\Controller
The Booking module is located inside a module directory in my project, and the module directory has been set as a Source Folder for my project:
Could anyone please help me find what setting I have to change to make namespaces auto generate as Booking\Controller instead of Booking\src\Controller?
Open Settings --> Directories;
Choose your ../module/Booking/src folder;
Right-click --> Mark as Sources;
On the right panel, you should see your folder (blue). Click on P with little arrow - Edit Root Properties. In input field Package prefix put as Booking;
Apply/Ok all windows
On screenshot, I have different paths, but you should get the gist.
Now in New Class dialog window in the field Namespace you can choose namespace between 'with src' and 'without'.

PhpStorm insert current namespace

I want the PhpStorm to insert current namespace by default or with a hotkey or with live templates.
Whet I create new Php class ("New | PHP Class" dialog) there is a field for a namespace. Is there a way for it to be filled automatically? It does not look a big deal because in my case a namespace is just directory path (I use composer) starting from src. My search efforts did not give my anything about this at all. Looks like PhpStrom does not have this feauture. But maybe there is some plugin or a hack?
New | PHP Class dialog should fill the namespace automatically based on the directory where file will be created. If it does not then you have not configured your project properly.
Settings/Preferences | Directories -- ensure that your src folder is marked as Source Root. That's depends on project, of course: for Laravel project you need to map app folder to App\ namespace (typical case).
PhpStorm can also detect source roots from your composer.json settings and can even keep it in sync since 2017.2 version (see https://blog.jetbrains.com/phpstorm/2017/07/configuring-with-composer-in-phpstorm-2017-2/).
Some links to read (official help pages):
https://www.jetbrains.com/help/phpstorm/configuring-php-namespaces-in-a-project.html
https://www.jetbrains.com/help/phpstorm/configuring-content-roots.html
https://www.jetbrains.com/help/phpstorm/directories.html

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 Ignore files/directories in TODO feature

Is it possible to exclude certain files from the TODO function in PhpStorm? For example, I'm using the highcharts javascript library. I don't want to see the few dozen or so TODO's they have marked mixed in with my own. I don't want to exclude this directory, because I still want to be able to view the files in a convenient manner.
In File > Settings > Scope add a new scope and make sure the files you like are green.
Open TODO Tab View > Tool Windows > TODO (Alt + 6)
In the top of TODOs click on Scope Based
Below select your new scope from step 1 below Custom Local Scopes
Yes, you can -- via custom scope that would include all but unwanted files/folders (Settings | Scopes) and then just choose it in TODO window.
Check these articles for details:
http://blog.jetbrains.com/webide/2012/10/managing-todo/
http://confluence.jetbrains.com/display/PhpStorm/Working+with+todo+comments+and+the+todo+tool+window
P.S.
This functionality is available since v6 only.
For libraries, there is a one click solution as I have just found out.
You can use the "External Libraries" feature to include the specific library folder, after which PHPStorm / IDEA will mark the folder as a library home and exclude it from inspection.
Note that you can include folders inside your project directroy, even though it's called "External" Libraries.
To exclude code (usually composer dependencies) from analysis.
Right click on desired folder
Click 'Mark Directory As'
Click 'Excluded'
Screenshot example below:

Script Task - Add existing file as link

I've been looking for an answer to this for a bit now but couldn't find anything. I was wondering if it is possible to add an existing file to the project created under the script task in an SSIS package. What I want to be able to do is to add one file called Helper or Utility to the solution and then add that file to all the script tasks for common functions. This is so if I change the class, it gets pushed through to all script tasks.
I know that I can add a reference to a DLL and add it to the GAC. I have tried this and it works. I've also tried adding the file to the projects and that works too.
This is just another solution that I'm trying, just in case I'm not able to deploy the DLL in prod. Any help will be appreciated. Thanks.
Firstly you need a master copy of your classes, you can copy them from an existing Script Task using the same process below but in reverse.
Open the Editor for the Script Task and on the Property Explorer click on the Project File (the st_[Guid] ), in the Properties window you’ll see the Project Folder location. (This location gets recreated every time you edit the script task)
In explorer, copy your classes to this folder
On the Project Explorer, click on the “Show All Files” icon
Right click on your files and add to Project
You can use regular VS functionality for linking files:
Right click your script project
Add > Existing item...
Select files to be included in your project
In the bottom right corner of the Open file dialog box you have a drop-down with 2 options: "Add" or "Add As Link" - select the latter one and you are done (see image below)
We can not use relative path after adding pages using Add link. Each user need to correct the path before running the project. The script task uses its own path.it doesn't run from package path which is the problem.