I am trying to make my php code psr-1 psr-2 compliant Don't i am getting some weird errors actually i am not understanding what exactly it want me to solve :(
Issue-1
Error: Opening parenthesis of a multi-line function call must be the last content on the line.
if (Configuration::updateValue('AV_GTC_CT_GT_DG_CT', $AV_GTC_CT) &&
Configuration::updateValue('AV_GTC_ST_CR_GP', $AV_GTC_ST) &&
Configuration::updateValue('AV_GTC_SD_NN_EA_AR_CN_AT_CT', $AV_GTC_SD) &&
Configuration::updateValue('AV_GTC_SD_NN_EA_AR_BK_CN', $AV_GTC_SD_NN_EA_AR_BK_CN) &&
Configuration::updateValue('AV_GTC_SW_GT_TO_CR_AT_BN_AT_OR_AS_PE',
$AV_GTC_SW_GT_TO_CR_AT_BN_AT_OR
) &&
Configuration::updateValue('AV_GTC_CN_CE_FR_LG_CR_CN', $AV_GTC_CN)
) {
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
Issue-2
Error:Expected "if (...) {\n"; found "if (...)\n {\n"
if (!$customer->isGuest())
{
return false;
}
Any Clue Guys?
Other code patches that are showing same errors
if (!$customer->isGuest()){
return false;
}
if (empty($password)){
$password = Tools::passwdGen();
}
if (empty($id_customer)||empty($id_guest)){
return false;
}
if (empty($id_guest) || empty($id_customer)){
return false;
}
Thanks!
Issue1:
&& should be on the next line
open ( and close ) should be in the same line for single line argument listing :)
can't format source here, external url: pastebin link
Issue2:
{ should be on the same line
if (!$customer->isGuest()) {
return false;
}
Related
I have this code:
function saveField($field, $id, $module, $value)
{
$bean = BeanFactory::getBean($module, $id);
if (is_object($bean) && $bean->id != "") {
if ($bean->field_defs[$field]['type'] == "multienum") {
$bean->$field = encodeMultienumValue($value);
}else if ($bean->field_defs[$field]['type'] == "relate" || $bean->field_defs[$field]['type'] == 'parent'){
$save_field = $bean->field_defs[$field]['id_name'];
$bean->$save_field = $value;
if ($bean->field_defs[$field]['type'] == 'parent') {
$bean->parent_type = $_REQUEST['parent_type'];
$bean->fill_in_additional_parent_fields(); // get up to date parent info as need it to display name
}
}else{
$bean->$field = $value;
}
//return here will work
$bean->save(); //this works
//nothing works here
return getDisplayValue($bean, $field);
} else {
return false;
}
}
The problem here is that anything under
$bean->save()
will not work. But I know that save is working as the values are being updated. So how can I debug this problem?
I already tried:
return var_dump($bean->save());
return print_r($bean->save());
if($bean->save()){
return "1";
}else{
return "2";
}
And none of those in the above worked I still get nothing in my return.
There is likely something such as an after_save logic hook that is executing and either causing a fatal error or doing an exit.
Try using xdebug, it should allow you to investigate further into the save method that fails.
I need to be able to catch an error. I have the following code
if($call['status_id'] != '' && $call['datetime_required'] != '')
{
//do stuff
}
else
{
// tell them how it failed
}
How would I go about displaying the section on which ti failed. So for example I can return a dynamic error message ie
return 'You did not fill in the field $errorField';
Where
$errorField
Is the if check on which it failed.
UPDATE
I currently code like so
if($call['status_id'] != '')
{
if ($call['datetime_required'] != '')
{
//do stuff
}
else
{
// tell them it failed due to the second condition
}
}
else
{
// tell them it failed due to the first condition
}
But would like to do the check in one line and change the message depending on where ti failed.
Note #jack had already posted his answer before this update.
I'm not sure I fully understand you, you mean something like this?
function check($call, $req_fields) {
$failed = array();
foreach($req_fields as $field) {
if(!$call[$field]) {
$failed[] = $field;
}
}
if(count($failed)) {
return join(', ', $failed) . ' are required.';
}
return 'success?' ;
}
$message = check($call, array('status_id', 'datetime_required'));
if($call['status_id'] != '')
{
if ($call['datetime_required'] != '')
//do stuff
}
else
{
// tell them it failed due to the second condition
}
}
else
{
// tell them it failed due to the first condition
}
something is wrong with my code formatting i believe
i am still unsure of what is happening that gives this error,
i am getting the error Parse error: syntax error, unexpected T_VARIABLE, expecting '('
here is my code
<?php
$runamazonapi = false;
if $runamazonapi = true
{
"run this code"
else
}
//do nothing
{
?>
i am getting the following error on line 3 or at this part
if $runamazonapi = true
thanks for your help in advance!!
<?php
$runamazonapi = false;
if ($runamazonapi == true)
{
"run this code"
}
else
//do nothing
{
}
?>
There are a number of syntactical errors with your code, but the error means that the php parser expected to find an ( but instead found a variable. You need () around the if statement condition and you need a closing } on the first if condition. Also, you need to use the proper {} to open and close the else clause:
<?php
$runamazonapi = false;
if ($runamazonapi = true)
{
"run this code"
}
else
{
//do nothing
}
?>
Also, what you have won't work. You're assigning $runamazonapi to true, not checking if it is true. You need to use == not =:
<?php
$runamazonapi = false;
if ($runamazonapi == true)
{
"run this code"
}
else
{
//do nothing
}
?>
try
if($runamazonapi){
//run code
}else{
//do something
}
I have a inputbox that displays a default text "Input Network ID Here...". I need to take $inputUri and check it against function checkUrl($string) to see if its still there. If the text hasn't been cleared then display the addError message
public function checkUrl($string)
{
$inputUri = 'Input Network ID Here...';
if(empty($string) || preg_match("#^([A-Z0-9][A-Z0-9_ -]*(?:.[A-Z0-9][A-Z0-9_ -]*)+):?(d+)?/?#i", $string))
{
return true;
}
else
{
if( isset($this) )
{
$this->addError("Input Network ID");
}
return false;
}
}
I think the problem is that the code is never entering the else block.
Perhaps you should change your first if line (line 3) to this:
if( (empty($string) || preg_match("#^([A-Z0-9][A-Z0-9_ -]*(?:.[A-Z0-9][A-Z0-9_ -]*)+):?(d+)?/?#i", $string) && $string != $inputUri )
I have used
if (!preg_match('/[a-z||0-9]#[a-z||0-9].[a-z]/', $email)) {
[PRINT ERROR]
}
&
if (!eregi( "^[0-9]+$", $email)) {
[PRINT ERROR]
}
&
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
[PRINT ERROR]
}
I have also tried taking out the ! and make it work backwards but for some reason NONE of those work to find out if it is valid. Any ideas why?...
I have it in an else if statement, Im not sure if that could be the cause..
I am using PHP
Try
'/[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4}/'
...
if (!preg_match('/[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4}/', strtoupper($email))) {
[PRINT ERROR]
}
As far as I can see, none of your regex expressions would match an email.
Try this from the Kohana source code:
function email($email)
{
return (bool) preg_match('/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+#(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD', (string) $email);
}
Check your php version. eregi is deprecated after 5.3.0. Also, the regex is not correct.
Try this (from wordpress):
// from wordpress code: wp-includes/formatting.php
function is_email($user_email)
{
$chars = "/^([a-z0-9+_]|\\-|\\.)+#(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
if (strpos($user_email, '#') !== false && strpos($user_email, '.') !== false)
{
if (preg_match($chars, $user_email)) {
return true;
} else {
return false;
}
} else {
return false;
}
}