How can i remove the missing subpackage error in a phpcs ruleset? - phpcodesniffer

I want to remove this because i dont need it on my project.
<rule ref="Squiz.Commenting.FileComment">
<properties>
<property name="subpackage" value="false"/>
</properties>
</rule>
See you

The way to exclude that specific error message in your ruleset.xml file is to use:
<exclude name="Squiz.Commenting.FileComment.MissingSubpackageTag" />
Use the -s command line argument to determine the code for a specific error message. You'll see something like this:
Missing #subpackage tag in file comment
(Squiz.Commenting.FileComment.MissingSubpackageTag)
If you want to exclude the whole sniff, you'd instead use:
<exclude name="Squiz.Commenting.FileComment" />
There are a lot of other things you can do in a ruleset file. See the docs for more examples: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml

Related

How do you enable document function in XSLT (called from ASP.NET)?

I have a stylesheet using a for each loop over the XML doc but when it comes accross using the document() method it fails.
<td >
<xsl:value-of select="document('Departments.xml')/Departments/Department[#Id=dep]/Name"/>
</td>
The variable has a value each loop which prints out
Execution of the "document()" function was prohibited. Use the
"XsltSettings.EnableDocumentFunction" property to enable it.
I think if XslCompiledTransform is used by the asp:xml control instead of XslTransform it means that the environment you are working in has set aspnet:RestrictXmlControls to true (https://learn.microsoft.com/en-us/previous-versions/aspnet/hh975440(v=vs.120))
<appSettings>
<add key="aspnet:RestrictXmlControls" value="true" />
</appSettings>
so you might need to try/check whether your locale web.config can set it back to
<appSettings>
<add key="aspnet:RestrictXmlControls" value="false" />
</appSettings>
to have XslTransform being used where you are not restricted by default XsltSettings.

Action form forward path not a url

What does it mean when I have a path like the example below in the first forward (then success forward)
<action
type="com.testpackage.servlettest"
path="/ClassHomepage"
scope="request">
<forward
name="success"
path=".class.homepage"
redirect="true" />
<forward
name="failure"
path="/Homepage.do"
module="/"
redirect="false" />
</action>
I understand the failure forward will forward to the page "/Homepage.do" if "failure" is returned
return mapping.findForward("failure");
But what happens if I return
return mapping.findForward("success");
What package will this try to load? How do I find out by looking at web.xml and struct-config.xml files?
You are using tiles, and you need to look in your tiles definition file (usually something like WEB-INF/tiles-defs.xml). Search for a <definition name=".class.homepage"> ... </definition> to find out which view it will direct to.

Populating choices in an ASP.NET ComboBox from web.config

There are several answered questions detailing how to refer to a single value from web.config file. I'd like to maintain lists of values with which to populate combo boxes in the Views. Should I use some sort of key/value pair structure, with the key identifying the particular combo box to populate?
<add key="CalculationMethod" value="Fixed"/>
<add key="CalculationMethod" value="Cost Plus"/>
<add key="CalculationMethod" value="Formula"/>
I'm not sure how I'd read this, or if that would even work (don't keys have to be unique?). The IntelliSense for web.config doesn't seem to allow much in the appSettings section that looks applicable to a more robust structure like
<list name="CalculationMethod">
<item value="Fixed"/>
<item value="Cost Plus"/>
<item value="Formula"/>
</list>
I see that the root <configuration> has a lot of options for children, but which one to use, if any?
You really should be using a database for something like this but if you must put it in the web.config then you could delimit the values and parse them out at run time.
<add key="CalculationMethod" value="Fixed,Cost Plus,Formula"/>
myComboBox.DataSource = new List<String>(lstrCalcMethodsFromWebConfig.Split(','));

Split appSettings into multiple sections / files?

Can I split appSettings into multiple external config files and include them in main web.config?
Here is what I have tried, but its not working :(
In web.config I defined a new section:
<configSections>
<section name="ssoConfiguration" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
below I have this section:
<ssoConfiguration>
<add key="SSOEnabled" value="true"/>
</ssoConfiguration>
When I call System.Configuration.ConfigurationManager.AppSettings["SSOEnabled"] it returns null.
Any ideas why?
Also, I will have multiple sections with such appSettins - is it possible to define them in multiple external config files and get them included in main web.config?
Thank you.
Because you're accessing AppSettings, but the "SSOEnabled" setting is in another section ("ssoConfiguration"). Try
var ssoConfiguration = (NameValueCollection)ConfigurationManager.GetSection("ssoConfiguration")
var ssoEnabled = ssoConfiguration["SSOEnabled"];

Web Deploy parameterization of an XML config file where settings are embedded in CDATA elements

During MSDEPLOY.EXE deployment, I am trying to squirt a parameter into an XML configuration file but the configuration values are stored in CDATA elements. Here are the contents of the file, called paths.xml:
<?xml version="1.0" encoding="UTF-8"?>
<course>
<questionnaires><![CDATA[https://www.site.com/somepage.asp]]></questionnaires>
</course>
I need to transform that URL into something different, but I can't figure out the correct XPATH and syntax for my parameters.xml file, here is what I've got now:
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<parameter name="QuestPath" description="Questionnaires path" defaultValue="<questionnaires><![CDATA[https://www.foo.com/somepage.asp]]></questionnaires>" tags="">
<parameterEntry kind="XmlFile" scope="paths.xml$" match="/course/questionnaires" />
</parameter>
</parameters>
I had very little luck referencing the CDATA element to replace it, so you can see I'm now trying to replace the entire questionnaire element including its CDATA contents. I had to do some escaping of the embedded angle-brackets so parameters.xml wasn't rejected due to invalid XML format.
Now, the resultant paths.xml ends up like:
<?xml version="1.0" encoding="UTF-8"?>
<course>
<questionnaires>https://www.foo.com/somepage.asp</questionnaires>
</course>
So, something has resolved the CDATA element down to its contents only, and CDATA no longer appears in paths.xml which I assume will cause the program that reads it to fail. Help!
Okay - I found a much simpler solution. In conjunction with the developer involved in housing this config XML file on our server, we changed it so the elements just contain the raw URLs, completely dispensing with the CDATA structures.
After testing that the consuming application still appeared to work fine, we agreed they were not needed and therefore I was able to do normal XmlFile replacements on nodes referenced like:
...match="/course/questionnaires/text()"

Resources