PhpStorm using incorrect namespaces - 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'.

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 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

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

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.

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.