I'm using PhpStorm with Symfony 3 to write my project.
But I've an issue. When I reformat the code,
This code :
Turns into this code :
And I don't know what is the setting I have to change to fix that :/ Any idea?
I found the solution for this at https://www.jetbrains.com/help/phpstorm/reformat-and-rearrange-code.html
First enable formatter markers in Settings->Editor->Tab:Formatter Control
After that, you can switch on/off the formatter on every statement/docblock via
// #formatter:off
or
/**
* #formatter:off
*/
be sure, that you enable the formatter with // #formatter:on if you want to format the code below your chained method call.
You change it in Menu:
File -> Default Settings -> Editor -> Code Style -> PHP
and overlap: Wrapping and Braces:
Chained method calls : "Wrap always"
Align when multiline "Y"
Place ';' on new Line "Y"
After it you can reformat yours code CTR+ALT+L
Related
I just added the PHP extension by Devsense to my VSCode and now it's lighting up like a Christmas tree. I want to disable the Intellisense option for unknown/undefined properties.
Here is the issue
and the error message
Undefined property: MY_Model::$load PHP(PHP0416)
And a link to the post where they talk about adding it
I saw some options for Intelliphense where you could set "intelephense.diagnostics.undefinedProperties": false
in the vscode settings.json, but I couldn't find anything that would work for this extension.
The fix described here in the 3rd post to add the property in a comment does work, but is not feasible in the codebases I am working in. I need something more like the second post, where I can just disable the check altogether
I found the answer to my own question. Leaving it here because It took me way too long.
You just have to exclude the error code, in this case error code 0416
1 - Open Settings.json : ctrl + shift + P and type 'settings.json'
2 - Select 'Open User Settings (JSON)
3 - At the end of file, add this code:
"php.problems.exclude" : {
"/" : [416],
"vendor/" : true,
}
I have enable the "editor.formatOnSave" setting but in php files when the code is formate, all the open brackets are going to a new line. i just want them to stay in the same line ex
function test{
}
not
function test
{
}
I am looking for a solution all day but i cant find anything
If you want to have your php code formatted like this
function test {
}
then use intelephense with the following settings.
"intelephense.format.braces": "k&r"
Edit
As #Pinonirvana said in his answer, you can now do this through the GUI.
You'll find this information under du user settings:
Short key -> Ctrl+,
or
File > Preferences > Settings
The new versions of VScode include this feature already.
You just need to search for "intelephense" in the VScode settings, and look for a setting called "Braces".
There is default formatter in the intelephence and it doesen't have many options to customize. You can disable it in the php language-specific settings:
~/.config/Code - OSS/User/settings.json:
----------
...
"[php]": {
// "editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
"editor.defaultFormatter": "kokororin.vscode-phpfmt"
},
...
Then you can use some another formatter that support customization, phpfmt for example. Here is my settings:
"phpfmt.exclude": [
"AllmanStyleBraces"
],
"phpfmt.smart_linebreak_after_curly": true,
"phpfmt.psr2": false,
"phpfmt.detect_indent": true
Easy Step, please follow below step -
I'm coding PHP and using a few extensions that are very useful:
PHP Formatter just for formatting code
PHP Intelephense for providing intellisense
In this case both of them are Formatting providers, so you can right click in your editor and select "Format document" and everything will get indented and beautiful.... you get the point.
The thing here is that the formatting done by the PHP Intelephense (which I don't like) is the one that stays.
If, for instance, I disable the Intelephense extension the formatting looks good.
Let me give you a visual difference between the two formatting:
Intelephense (bad):
if ($condition) {
doSomthing();
}
else {
doAnotherThing();
}
PHP formatter (good) [chek out the else]
if ($condition) {
doSomthing();
} else {
doAnotherThing();
}
Zanks in advance for your time
"intelephense.format.enable": false
This will do your work.
There is no generic way to choose one over the other. This is left to extension authors to handle via settings as explained in the docs here
What happens when there are multiple formatters for one language? This
can be a problem when different formatters' actions contradict. In the
October release, we added settings to enable or disable the default
formatters that ship with VS Code. The best practice is for extension
authors to add a similar setting as what we did in VS Code as shown
below.
"html.format.enable": true,
"javascript.format.enable": true,
"typescript.format.enable": true,
"json.format.enable": true
You can read more discussion on how they came to this in this github issue.
So what does this mean for you? It means that the intelliphense extension needs to add a setting to disable formatting. You can create an issue and wait for them to fix it or try to make a PR to fix it yourself.
Recently I've started using PHP (worked for MS shops since graduating, and that was mostly what I used in college too). To help with this, I'm using Netbeans and am in the process of configuring it so that it's more similar to Visual Studio.
Under Options -> Editor -> Formatting, I've found this setting highlighted in the red box:
Any setting I pick for that value makes no difference in the sample file on the right. I copied the text from when I use the "Same Line" value and did a diff on it against the text when using "New Line" and they're identical.
So, what is this setting?
In the example to the right of the options, I thought this would impact the (new Example())->alignParamsExample(... and push anything after the -> onto a New Line, but that's not the case.
I've also read the documentation about traits but I'm still unclear exactly as to what the "trait body" would be. I typed out the code they provided in "Example #2 Precedence Order Example" but noticed no behavioral difference in the IDE.
I've tagged this question with both Netbeans and php tags; if I select other languages this option isn't present (but I only have HTML, JSON, Javascript, and PHP to chose from) so I wasn't sure if this is a "PHP thing" or a "Netbeans thing." If it's explicitly one or the other, let me know and I'll remove the tag.
I think this is about that block in class:
class ExampleClass
{
/** Start of Use Trait Body **/
use TraitOne;
use TraitTwo;
use TraitThree;
/** End of Use Trait Body **/
}
How can I add comments in PHP eclipse? I'm trying by selecting few lines of code, then right click, On menu, "Source" and then I have tried all these options there "general element comment", "toggle comment", "Add block comment". None of them works.
PS. I just downloaded latest eclipse PHP version.
Try Ctrl+Shift+/
The question is similair to How to comment a block in Eclipse?
Why don't you just try adding /** + enter? It will produce something like
/**
* Comment here
*/
Remember to follow the doc order
/**
* Description
* #param argument/parameter
* #return
*/
It`s a bug in latest PHP eclipse. Fix is here.
I was using single line comments on my eclipse php project. When i uploaded it to server ,some obfuscation has been applied automatically.Hence all the line breaks are removed and it treating the whole program as a single line. so i am getting an END OF STATEMENT error on server.So its better to use /--/ instead of //---- while commenting.