idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
51,400
private function _detectVisibility ( $ token ) { if ( $ this -> tokenizer -> checkToken ( $ token , T_PRIVATE ) ) { $ this -> _functionVisibility = 'PRIVATE' ; } else if ( $ this -> tokenizer -> checkToken ( $ token , T_PROTECTED ) ) { $ this -> _functionVisibility = 'PROTECTED' ; } else if ( $ this -> tokenizer -> checkToken ( $ token , T_STATIC ) ) { $ this -> _functionStatic = true ; } }
Process a function parameters to detect visibility and staticity .
51,401
private function _processSwitchStop ( ) { if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_CASE || $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_DEFAULT ) { $ this -> _checkSwitchCaseNeedBreak ( ) ; $ this -> statementStack -> pop ( ) ; } $ this -> _checkSwitchNeedDefault ( ) ; }
Process the end of a switch block .
51,402
private function _checkSwitchNeedDefault ( ) { if ( $ this -> _isActive ( 'switchNeedDefault' ) ) { if ( ! $ this -> statementStack -> getCurrentStackItem ( ) -> switchHasDefault ) { $ this -> _writeError ( 'switchNeedDefault' , $ this -> _getMessage ( 'SWITCH_DEFAULT' ) , $ this -> _switchStartLine , $ this -> _config -> getTestLevel ( 'switchNeedDefault' ) ) ; } } }
Check if the default case of a switch statement is present .
51,403
private function _processSwitchCase ( ) { if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_CASE || $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_DEFAULT ) { $ this -> _checkSwitchCaseNeedBreak ( ) ; $ this -> statementStack -> pop ( ) ; } $ this -> _checkSwitchDefaultOrder ( ) ; $ stackitem = new StatementItem ( ) ; $ stackitem -> line = $ this -> lineNumber ; $ stackitem -> type = "CASE" ; $ stackitem -> name = "case" ; $ this -> statementStack -> push ( $ stackitem ) ; $ this -> statementStack -> getCurrentStackItem ( ) -> caseHasBreak = false ; $ this -> statementStack -> getCurrentStackItem ( ) -> caseStartLine = $ this -> lineNumber ; $ startPos = $ this -> tokenizer -> findNextStringPosition ( ":" , $ this -> tokenizer -> getCurrentPosition ( ) ) ; $ this -> statementStack -> getCurrentStackItem ( ) -> caseIsEmpty = $ this -> tokenizer -> checkNextValidToken ( T_CASE , false , $ startPos + 1 ) || $ this -> tokenizer -> checkNextValidToken ( T_DEFAULT , false , $ startPos + 1 ) ; }
Process a case statement .
51,404
private function _processSwitchDefault ( ) { if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_CASE || $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_DEFAULT ) { $ this -> _checkSwitchCaseNeedBreak ( ) ; $ this -> statementStack -> pop ( ) ; } $ this -> statementStack -> getCurrentStackItem ( ) -> switchHasDefault = true ; $ stackitem = new StatementItem ( ) ; $ stackitem -> line = $ this -> lineNumber ; $ stackitem -> type = "DEFAULT" ; $ stackitem -> name = "default" ; $ this -> statementStack -> push ( $ stackitem ) ; }
Process a default statement .
51,405
private function _processInterfaceStatement ( ) { $ this -> _checkDocExists ( T_INTERFACE ) ; $ this -> _ncssTotalInterfaces ++ ; $ this -> _ncssFileInterfaces ++ ; if ( $ this -> _isActive ( 'oneInterfacePerFile' ) && $ this -> _ncssFileInterfaces > 1 ) { $ msg = $ this -> _getMessage ( 'ONE_INTERFACE_PER_FILE' , $ this -> _currentFilename ) ; $ this -> _writeError ( 'oneInterfacePerFile' , $ msg ) ; } $ this -> _inFunction = false ; $ this -> _nbFunctionParameters = 0 ; $ this -> _functionParameters = array ( ) ; $ this -> _inFunctionStatement = false ; $ this -> _functionReturns = false ; $ this -> _functionThrows = false ; $ this -> _inControlStatement = false ; $ this -> _currentStatement = false ; $ this -> _inInterfaceStatement = true ; while ( ! $ this -> tokenizer -> checkCurrentToken ( T_STRING ) ) { $ this -> tokenizer -> getNextToken ( ) ; } $ token = $ this -> tokenizer -> getCurrentToken ( ) ; $ interfacename = $ token -> text ; $ this -> _currentInterfacename = $ interfacename ; $ this -> _checkTypeNameFileNameMatch ( $ interfacename ) ; $ this -> _checkInterfaceNaming ( $ interfacename ) ; $ this -> _checkWhiteSpaceAfter ( $ interfacename ) ; }
Process an interface declaration statement .
51,406
private function _processClassStatement ( ) { $ isAfterScopeResolutionOperator = $ this -> tokenizer -> checkPreviousToken ( T_DOUBLE_COLON ) ; if ( $ isAfterScopeResolutionOperator ) { return ; } $ this -> _checkDocExists ( T_CLASS ) ; $ this -> _ncssTotalClasses ++ ; $ this -> _ncssFileClasses ++ ; if ( $ this -> _isActive ( 'oneClassPerFile' ) && $ this -> _ncssFileClasses > 1 ) { $ msg = $ this -> _getMessage ( 'ONE_CLASS_PER_FILE' , $ this -> _currentFilename ) ; $ this -> _writeError ( 'oneClassPerFile' , $ msg ) ; } $ this -> _inFunction = false ; $ this -> _nbFunctionParameters = 0 ; $ this -> _functionParameters = array ( ) ; $ this -> _inFunctionStatement = false ; $ this -> _functionReturns = false ; $ this -> _functionThrows = false ; $ this -> _inControlStatement = false ; $ this -> _currentStatement = false ; $ this -> _inClassStatement = true ; while ( ! $ this -> tokenizer -> checkCurrentToken ( T_STRING ) ) { $ this -> tokenizer -> getNextToken ( ) ; } $ token = $ this -> tokenizer -> getCurrentToken ( ) ; $ classname = $ token -> text ; $ this -> _currentClassname = $ classname ; $ this -> _checkTypeNameFileNameMatch ( $ classname ) ; $ this -> _checkClassNaming ( $ classname ) ; $ this -> _checkWhiteSpaceAfter ( $ classname ) ; }
Process a class declaration statement .
51,407
private function _checkEmptyBlock ( ) { if ( $ this -> _isActive ( 'checkEmptyBlock' ) && $ this -> _currentStatement ) { if ( $ this -> tokenizer -> checkNextValidToken ( T_BRACES_CLOSE ) ) { $ msg = $ this -> _getMessage ( 'EMPTY_BLOCK' , $ this -> _currentStatement ) ; $ this -> _writeError ( 'checkEmptyBlock' , $ msg ) ; } } }
Check for empty block .
51,408
private function _checkEncapsedVariablesInsideString ( ) { if ( $ this -> _isActive ( 'encapsedVariablesInsideString' ) && ( ! $ this -> statementStack -> getCurrentStackItem ( ) -> inHeredoc || ( $ this -> _inFuncCall && ! $ this -> _config -> isException ( 'encapsedVariablesInsideString' , end ( $ this -> _currentFuncCall ) ) ) ) ) { $ this -> _writeError ( 'encapsedVariablesInsideString' , $ this -> _getMessage ( 'VARIABLE_INSIDE_STRING' ) ) ; } }
Check for encapsed variables inside string .
51,409
private function _checkStrictCompare ( $ text ) { if ( $ this -> _isActive ( 'strictCompare' ) ) { $ message = $ this -> _getMessage ( 'USE_STRICT_COMPARE' , $ text ) ; $ this -> _writeError ( 'strictCompare' , $ message ) ; } }
Check for potential bugs when using comparison operator .
51,410
private function _checkInnerAssignment ( ) { if ( $ this -> _isActive ( 'checkInnerAssignment' ) && $ this -> _inControlStatement ) { if ( ! $ this -> _config -> isException ( 'checkInnerAssignment' , $ this -> _currentStatement ) ) { $ this -> _writeError ( 'checkInnerAssignment' , $ this -> _getMessage ( 'INSIDE_ASSIGNMENT' ) ) ; } } }
Check for inner assignments .
51,411
private function _checkEmptyStatement ( ) { if ( $ this -> _isActive ( 'checkEmptyStatement' ) ) { if ( $ this -> tokenizer -> checkNextValidToken ( T_SEMICOLON ) ) { $ this -> _writeError ( 'checkEmptyStatement' , $ this -> _getMessage ( 'EMPTY_STATEMENT' ) ) ; } } }
Check for empty statement .
51,412
private function _checkUnusedPrivateFunctions ( ) { if ( $ this -> _isActive ( 'checkUnusedPrivateFunctions' ) ) { $ uncalledFunctions = array_diff ( $ this -> _privateFunctions , $ this -> _usedFunctions ) ; foreach ( $ uncalledFunctions as $ uncalledFunction ) { $ msg = $ this -> _getMessage ( 'UNUSED_PRIVATE_FUNCTION' , $ uncalledFunction ) ; $ this -> _writeError ( 'checkUnusedPrivateFunctions' , $ msg , $ this -> _privateFunctionsStartLines [ $ uncalledFunction ] , $ this -> _config -> getTestLevel ( 'checkUnusedPrivateFunctions' ) ) ; } } }
Check for unused functions .
51,413
private function _checkUnusedVariables ( ) { if ( $ this -> _isActive ( 'checkUnusedVariables' ) ) { foreach ( $ this -> _variables as $ variable ) { if ( ( ! $ variable -> isUsed ) && ! ( $ this -> _isClass || $ this -> _isView ) && ! $ this -> _config -> isException ( 'checkUnusedVariables' , $ variable -> name ) ) { $ msg = $ this -> _getMessage ( 'UNUSED_VARIABLE' , $ variable -> name ) ; $ this -> _writeError ( 'checkUnusedVariables' , $ msg , $ variable -> line , $ this -> _config -> getTestLevel ( 'checkUnusedVariables' ) ) ; } } } }
Check for unused variables in the file .
51,414
private function _checkUnusedCode ( $ endToken ) { if ( $ this -> _isActive ( 'checkUnusedCode' ) ) { if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_FUNCTION ) { $ pos = $ this -> tokenizer -> findNextStringPosition ( ';' ) ; $ nextValidToken = $ this -> tokenizer -> peekNextValidToken ( $ pos + 1 ) ; $ posClose = $ this -> tokenizer -> findNextStringPosition ( '}' ) ; if ( $ nextValidToken !== null && $ posClose > $ nextValidToken -> position ) { $ msg = $ this -> _getMessage ( 'UNUSED_CODE' , $ this -> statementStack -> getCurrentStackItem ( ) -> name , $ endToken ) ; $ this -> _writeError ( 'checkUnusedCode' , $ msg ) ; } } } }
Check for unused code .
51,415
private function _checkUnusedFunctionParameters ( ) { if ( $ this -> _isActive ( 'checkUnusedFunctionParameters' ) ) { if ( ! $ this -> statementStack -> getParentStackItem ( ) -> docblocInheritDoc ) { foreach ( $ this -> _functionParameters as $ variableName => $ value ) { if ( $ value !== "used" ) { $ msg = $ this -> _getMessage ( 'UNUSED_FUNCTION_PARAMETER' , $ this -> _currentFunctionName , $ variableName ) ; $ this -> _writeError ( 'checkUnusedFunctionParameters' , $ msg ) ; } } } } }
Check for unused function parameters .
51,416
private function _processVariable ( $ text ) { if ( ! in_array ( $ text , $ this -> _systemVariables ) ) { $ this -> _checkVariableNaming ( $ text ) ; } $ this -> _checkVariableNameLength ( $ text ) ; $ this -> _checkDeprecation ( $ text ) ; $ this -> _checkReplacements ( $ text ) ; if ( ! empty ( $ this -> _functionParameters [ $ text ] ) && $ this -> _inFunction ) { $ this -> _functionParameters [ $ text ] = "used" ; } else if ( ! $ this -> _inFunctionStatement ) { $ pos = $ this -> tokenizer -> getCurrentPosition ( ) ; $ nextTokenInfo = $ this -> tokenizer -> peekNextValidToken ( $ pos + 1 ) ; $ nextTokenText = $ nextTokenInfo -> text ; $ affectionTokens = array ( '=' , '+=' , '*=' , '/=' , '-=' , '%=' , '&=' , '|=' , '^=' , '<<=' , '>>=' , '.=' ) ; $ isAffectation = in_array ( $ nextTokenText , $ affectionTokens ) ; if ( empty ( $ this -> _variables [ $ text ] ) && ! in_array ( $ text , $ this -> _systemVariables ) ) { $ variable = new VariableInfo ( ) ; $ variable -> name = $ text ; $ variable -> line = $ this -> lineNumber ; $ this -> _variables [ $ text ] = $ variable ; } else if ( $ isAffectation ) { } else { if ( $ text === '$this' ) { $ nextTokenInfo2 = $ this -> tokenizer -> peekNextValidToken ( $ nextTokenInfo -> position ) ; if ( $ this -> tokenizer -> checkToken ( $ nextTokenInfo2 , T_OBJECT_OPERATOR ) ) { if ( $ this -> _functionStatic ) { if ( $ this -> _isActive ( 'thisInStatic' ) ) { $ this -> _writeError ( 'thisInStatic' , $ this -> _getMessage ( 'THIS_IN_STATIC_FUNCTION' ) ) ; } } $ nextTokenInfo3 = $ this -> tokenizer -> peekNextValidToken ( $ nextTokenInfo2 -> position + 1 ) ; $ text = '$' . $ nextTokenInfo3 -> text ; } } if ( ! empty ( $ this -> _variables [ $ text ] ) ) { $ variable = $ this -> _variables [ $ text ] ; $ variable -> isUsed = true ; $ this -> _variables [ $ text ] = $ variable ; } } } }
Check the variable use .
51,417
private function _processReturn ( ) { if ( ! $ this -> tokenizer -> checkNextValidToken ( T_SEMICOLON ) ) { $ this -> _functionReturns = true ; } $ this -> _checkUnusedCode ( 'RETURN' ) ; }
Process the return token .
51,418
private function _checkWhiteSpaceBefore ( $ text ) { if ( $ this -> _isActive ( 'checkWhiteSpaceBefore' ) ) { if ( ! $ this -> _config -> isException ( 'checkWhiteSpaceBefore' , $ text ) ) { if ( ! $ this -> tokenizer -> checkPreviousToken ( T_WHITESPACE ) ) { $ msg = $ this -> _getMessage ( 'SPACE_BEFORE_TOKEN' , $ text ) ; $ this -> _writeError ( 'checkWhiteSpaceBefore' , $ msg ) ; } } } }
Check for the presence of a white space before the text .
51,419
private function _checkNoWhiteSpaceBefore ( $ text ) { if ( $ this -> _isActive ( 'noSpaceBeforeToken' ) ) { if ( ! $ this -> _config -> isException ( 'noSpaceBeforeToken' , $ text ) ) { if ( $ this -> tokenizer -> checkPreviousToken ( T_WHITESPACE ) ) { $ prevValid = $ this -> tokenizer -> peekPrvsValidToken ( ) ; $ currentToken = $ this -> tokenizer -> getCurrentToken ( ) ; if ( $ prevValid -> line === $ currentToken -> line ) { $ msg = $ this -> _getMessage ( 'NO_SPACE_BEFORE_TOKEN' , $ text ) ; $ this -> _writeError ( 'noSpaceBeforeToken' , $ msg ) ; } } } } }
Check for the absence of a white space before the text .
51,420
private function _checkWhiteSpaceAfter ( $ text ) { if ( $ this -> _isActive ( 'checkWhiteSpaceAfter' ) ) { if ( ! $ this -> _config -> isException ( 'checkWhiteSpaceAfter' , $ text ) ) { if ( ! $ this -> tokenizer -> checkNextToken ( T_WHITESPACE ) ) { if ( ! ( $ this -> tokenizer -> checkNextToken ( T_NEW_LINE ) || $ this -> tokenizer -> checkNextToken ( T_CLOSE_TAG ) ) ) { $ msg = $ this -> _getMessage ( 'SPACE_AFTER_TOKEN' , $ text ) ; $ this -> _writeError ( 'checkWhiteSpaceAfter' , $ msg ) ; } } } } }
Check for the presence of a white space after the text .
51,421
private function _checkNoWhiteSpaceAfter ( $ token ) { if ( $ this -> _isActive ( 'noSpaceAfterToken' ) ) { $ text = $ token -> text ; if ( ! $ this -> _config -> isException ( 'noSpaceAfterToken' , $ text ) ) { if ( $ this -> tokenizer -> checkNextToken ( T_WHITESPACE ) ) { $ tokenAfter = $ this -> tokenizer -> peekNextValidToken ( ) ; if ( $ tokenAfter -> line === $ token -> line ) { $ msg = $ this -> _getMessage ( 'NO_SPACE_AFTER_TOKEN' , $ text ) ; $ this -> _writeError ( 'noSpaceAfterToken' , $ msg ) ; } } } } }
Check for the absence of a white space after the text .
51,422
private function _checkLargeLine ( ) { $ checkHTMLLines = $ this -> _config -> getTestProperty ( 'lineLength' , 'checkHTMLLines' ) ; if ( $ checkHTMLLines === "true" || ! $ this -> tokenizer -> checkNextValidToken ( T_INLINE_HTML ) ) { $ maxLength = $ this -> _config -> getTestProperty ( 'lineLength' , 'maxLineLength' ) ; $ lineString = "" ; $ currentTokenIndex = $ this -> tokenizer -> getCurrentPosition ( ) ; $ currentToken = $ this -> tokenizer -> getCurrentToken ( $ currentTokenIndex ) ; do { $ currentTokenString = $ currentToken -> text ; $ lineString .= $ currentTokenString ; $ currentTokenIndex += 1 ; $ currentToken = $ this -> tokenizer -> peekTokenAt ( $ currentTokenIndex ) ; $ isNull = ( $ currentToken === null ) ; $ isNewLine = ! $ isNull && $ this -> tokenizer -> checkToken ( $ currentToken , T_NEW_LINE ) ; } while ( ! ( $ isNull || $ isNewLine ) ) ; $ lineLength = strlen ( $ lineString ) ; if ( $ lineLength > $ maxLength ) { if ( strpos ( $ lineString , "/*" ) ) { return ; } $ msg = $ this -> _getMessage ( 'LONG_LINE' , $ lineLength , $ maxLength ) ; $ this -> _writeError ( 'lineLength' , $ msg ) ; } } }
Check if the current line exceeds the maxLineLength allowed .
51,423
private function _checkIndentation ( $ token ) { $ whitespaceString = $ token -> text ; if ( $ this -> _isActive ( 'indentation' ) ) { $ indentationType = $ this -> _config -> getTestProperty ( 'indentation' , 'type' ) ; if ( strtolower ( $ indentationType ) === 'space' || strtolower ( $ indentationType ) === 'spaces' ) { $ tabfound = preg_match ( "/\t/" , $ whitespaceString ) ; if ( $ tabfound ) { $ this -> _writeError ( 'indentation' , $ this -> _getMessage ( 'INDENTATION_TAB' ) , $ token -> line ) ; } $ this -> _checkIndentationLevel ( $ token ) ; } else if ( strtolower ( $ indentationType ) === 'tab' || strtolower ( $ indentationType ) === 'tabs' ) { $ whitespacefound = preg_match ( "/[ ]/" , $ whitespaceString ) ; if ( $ whitespacefound ) { $ this -> _writeError ( 'indentation' , $ this -> _getMessage ( 'INDENTATION_WHITESPACE' ) , $ token -> line ) ; } } } }
Checks for presence of tab in the whitespace character string .
51,424
private function _checkIndentationLevel ( $ token ) { $ whitespaceString = $ token -> text ; $ indentationNumber = $ this -> _config -> getTestProperty ( 'indentation' , 'number' ) ; if ( empty ( $ indentationNumber ) ) { $ indentationNumber = 4 ; } if ( ! $ this -> _inClass ) { return ; } if ( $ this -> _inControlStatement || $ this -> _inFuncCall || ! isset ( $ this -> lineNumber ) || $ this -> tokenizer -> checkNextToken ( T_NEW_LINE ) || $ this -> tokenizer -> checkNextValidToken ( T_PARENTHESIS_CLOSE ) || $ this -> tokenizer -> checkNextValidToken ( T_BOOLEAN_AND ) || $ this -> tokenizer -> checkNextValidToken ( T_BOOLEAN_OR ) || $ this -> tokenizer -> checkNextValidToken ( T_OBJECT_OPERATOR ) ) { return ; } $ previousToken = $ this -> tokenizer -> peekPrvsToken ( ) ; if ( ! isset ( $ this -> indentationLevel [ 'previousLine' ] ) || $ this -> lineNumber !== $ this -> indentationLevel [ 'previousLine' ] ) { $ nesting = $ this -> statementStack -> count ( ) ; if ( $ this -> tokenizer -> checkNextValidToken ( T_BRACES_CLOSE ) || $ this -> tokenizer -> checkNextValidToken ( T_SQUARE_BRACKET_CLOSE ) ) { $ nesting -- ; } $ expectedIndentation = $ nesting * $ indentationNumber ; $ indentation = strlen ( $ whitespaceString ) ; if ( $ previousToken -> id !== T_NEW_LINE ) { $ indentation = 0 ; } if ( $ this -> tokenizer -> checkNextToken ( T_COMMENT ) ) { return ; } if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_SWITCH ) { if ( $ this -> tokenizer -> checkNextValidToken ( T_BRACES_OPEN ) || $ this -> tokenizer -> checkNextValidToken ( T_BRACES_CLOSE ) ) { return ; } } else if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_CASE || $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_DEFAULT ) { if ( $ this -> tokenizer -> checkNextValidToken ( T_CASE ) || $ this -> tokenizer -> checkNextValidToken ( T_DEFAULT ) || $ this -> tokenizer -> checkNextValidToken ( T_BRACES_CLOSE ) ) { $ expectedIndentation -= $ indentationNumber ; } } if ( $ expectedIndentation !== $ indentation ) { $ msg = $ this -> _getMessage ( 'INDENTATION_LEVEL' , $ expectedIndentation , $ indentation ) ; $ this -> _writeError ( 'indentationLevel' , $ msg , $ token -> line ) ; } } $ this -> indentationLevel [ 'previousLine' ] = $ this -> lineNumber ; }
Check the indentation level .
51,425
private function _checkNeedBraces ( ) { if ( $ this -> _isActive ( 'needBraces' ) ) { $ stmt = strtolower ( $ this -> _currentStatement ) ; if ( in_array ( $ stmt , array ( 'if' , 'elseif' , 'do' , 'for' , 'foreach' ) ) || ( $ stmt === "while" && ! $ this -> statementStack -> getParentStackItem ( ) -> afterDoStatement ) ) { if ( ! $ this -> tokenizer -> checkNextValidToken ( T_BRACES_OPEN ) ) { $ msg = $ this -> _getMessage ( 'NEED_BRACES' , $ stmt ) ; $ this -> _writeError ( 'needBraces' , $ msg ) ; } } else if ( $ stmt === "else" ) { if ( ! $ this -> tokenizer -> checkNextValidToken ( T_BRACES_OPEN ) && ! $ this -> tokenizer -> checkNextValidToken ( T_IF ) ) { $ msg = $ this -> _getMessage ( 'NEED_BRACES' , $ stmt ) ; $ this -> _writeError ( 'needBraces' , $ msg ) ; } } if ( $ stmt === "while" ) { $ this -> statementStack -> getCurrentStackItem ( ) -> afterDoStatement = false ; } } }
Checks if the block of code need braces .
51,426
private function _processComment ( $ token ) { if ( $ token -> id === T_COMMENT ) { $ this -> _ncssTotalSingleComment ++ ; $ this -> _ncssFileSingleComment ++ ; } else if ( $ token -> id === T_ML_COMMENT ) { $ this -> _ncssTotalMultiComment ++ ; $ this -> _ncssFileMultiComment ++ ; } else if ( $ token -> id === T_DOC_COMMENT ) { $ this -> _ncssTotalPhpdoc ++ ; $ this -> _ncssFilePhpdoc ++ ; $ this -> _ncssTotalLinesPhpdoc ++ ; $ this -> _ncssFileLinesPhpdoc ++ ; if ( $ this -> _isFileDocComment ( ) ) { $ this -> _processAnnotation ( T_FILE , $ token -> text ) ; } } if ( stripos ( $ token -> text , '/**' ) !== false ) { $ this -> statementStack -> getCurrentStackItem ( ) -> docblocNbParams = 0 ; $ this -> statementStack -> getCurrentStackItem ( ) -> docblocNbReturns = 0 ; $ this -> statementStack -> getCurrentStackItem ( ) -> docblocNbThrows = 0 ; } if ( stripos ( $ token -> text , '@param' ) !== false ) { $ this -> statementStack -> getCurrentStackItem ( ) -> docblocNbParams ++ ; } if ( stripos ( $ token -> text , '@return' ) !== false ) { $ this -> statementStack -> getCurrentStackItem ( ) -> docblocNbReturns ++ ; } if ( stripos ( $ token -> text , '@throw' ) !== false ) { $ this -> statementStack -> getCurrentStackItem ( ) -> docblocNbThrows ++ ; } if ( stripos ( $ token -> text , '@inheritdoc' ) !== false ) { $ this -> statementStack -> getCurrentStackItem ( ) -> docblocInheritDoc = true ; } if ( $ this -> _isActive ( 'noShellComments' ) ) { $ todoStr = strpos ( $ token -> text , '#' ) ; if ( $ todoStr === 0 ) { $ this -> _writeError ( 'noShellComments' , $ this -> _getMessage ( 'NO_SHELL_COMMENTS' ) ) ; } } $ this -> _processTODO ( $ token ) ; }
Process a comment .
51,427
private function _processAnnotation ( $ token , $ comment ) { $ subToken = strtok ( $ comment , PHP_EOL ) ; while ( $ subToken !== false ) { $ pos = stripos ( $ subToken , "@SuppressWarnings" ) ; if ( $ pos !== false ) { $ suppressedCheck = trim ( substr ( $ subToken , $ pos + strlen ( "@SuppressWarnings" ) ) ) ; $ supprArray = explode ( ' ' , $ suppressedCheck ) ; foreach ( $ supprArray as $ supprCheck ) { $ suppressedCheck = trim ( $ supprCheck ) ; if ( $ token === T_CLASS ) { $ this -> _classSuppressWarnings [ ] = $ suppressedCheck ; } elseif ( $ token === T_INTERFACE ) { $ this -> _interfaceSuppressWarnings [ ] = $ suppressedCheck ; } elseif ( $ token === T_FUNCTION ) { $ this -> _functionSuppressWarnings [ ] = $ suppressedCheck ; } elseif ( $ token === T_FILE ) { $ this -> _fileSuppressWarnings [ ] = $ suppressedCheck ; } } } $ subToken = strtok ( PHP_EOL ) ; } }
Process PHP_DOC looking for annotations .
51,428
private function _checkSilenced ( $ text ) { if ( $ this -> _isActive ( 'checkSilencedError' ) ) { if ( ! $ this -> _config -> isException ( 'checkSilencedError' , $ text ) ) { $ previousToken = $ this -> tokenizer -> peekPrvsToken ( ) ; if ( $ previousToken -> id === T_AROBAS ) { $ this -> _writeError ( 'checkSilencedError' , $ this -> _getMessage ( 'SILENCED_ERROR' ) ) ; } } } }
Check for silenced call to functions .
51,429
private function _checkMandatoryHeader ( ) { if ( $ this -> _isActive ( 'mandatoryHeader' ) ) { $ expectedHeader = $ this -> _config -> getTestProperty ( 'mandatoryHeader' , 'header' ) ; $ expectedHeader = trim ( $ expectedHeader ) ; $ expectedHeader = preg_replace ( '~[\r\n\t ]+~' , '' , $ expectedHeader ) ; $ filecontent = $ this -> tokenizer -> content ; $ filecontent = preg_replace ( '~[\r\n\t ]+~' , '' , $ filecontent ) ; if ( strpos ( $ filecontent , $ expectedHeader ) === FALSE ) { $ this -> _writeError ( 'mandatoryHeader' , $ this -> _getMessage ( 'MANDATORY_HEADER' ) ) ; } } }
Check for the presence of a mandatory header .
51,430
private function _checkDeprecation ( $ text ) { if ( $ this -> _isActive ( 'checkDeprecation' ) ) { $ key = strtolower ( $ text ) ; if ( array_key_exists ( $ key , $ this -> _deprecatedFunctions ) ) { $ msg = $ this -> _getMessage ( 'DEPRECATED_FUNCTION' , $ this -> _deprecatedFunctions [ $ key ] [ 'old' ] , $ this -> _deprecatedFunctions [ $ key ] [ 'version' ] , $ this -> _deprecatedFunctions [ $ key ] [ 'new' ] ) ; $ this -> _writeError ( 'checkDeprecation' , $ msg ) ; } } }
Check for deprecated functions .
51,431
private function _checkProhibitedFunctions ( $ functionName ) { if ( $ this -> _isActive ( 'checkProhibitedFunctions' ) ) { if ( in_array ( $ functionName , $ this -> _prohibitedFunctions ) ) { $ msg = $ this -> _getMessage ( 'PROHIBITED_FUNCTION' , $ functionName ) ; $ this -> _writeError ( 'checkProhibitedFunctions' , $ msg ) ; } } }
Check for prohibited functions .
51,432
private function _checkAliases ( $ text ) { if ( $ this -> _isActive ( 'checkAliases' ) ) { $ key = strtolower ( $ text ) ; if ( array_key_exists ( $ key , $ this -> _aliasedFunctions ) ) { $ msg = $ this -> _getMessage ( 'ALIASED_FUNCTION' , $ this -> _aliasedFunctions [ $ key ] [ 'old' ] , $ this -> _aliasedFunctions [ $ key ] [ 'new' ] ) ; $ this -> _writeError ( 'checkAliases' , $ msg ) ; } } }
Check for aliased functions .
51,433
private function _checkReplacements ( $ text ) { if ( $ this -> _isActive ( 'checkReplacements' ) ) { $ key = strtolower ( $ text ) ; if ( array_key_exists ( $ key , $ this -> _replacements ) ) { $ msg = $ this -> _getMessage ( 'REPLACED' , $ this -> _replacements [ $ key ] [ 'old' ] , $ this -> _replacements [ $ key ] [ 'new' ] ) ; $ this -> _writeError ( 'checkReplacements' , $ msg ) ; } } }
Check for replaced functions .
51,434
private function _checkShortOpenTag ( $ token ) { if ( $ this -> _isActive ( 'noShortPhpCodeTag' ) ) { $ shortOpenTagPos = strpos ( $ token -> text , '<?php' ) ; if ( $ shortOpenTagPos === false ) { $ this -> _writeError ( 'noShortPhpCodeTag' , $ this -> _getMessage ( 'WRONG_OPEN_TAG' ) ) ; } } }
Check for short open tag .
51,435
private function _isActive ( $ check ) { $ test = $ this -> _config -> getTest ( $ check ) ; $ active = ! empty ( $ test ) ; $ active = $ active && ! ( in_array ( $ check , $ this -> _functionSuppressWarnings ) || in_array ( $ check , $ this -> _classSuppressWarnings ) || in_array ( $ check , $ this -> _interfaceSuppressWarnings ) || in_array ( $ check , $ this -> _fileSuppressWarnings ) ) ; return $ active ; }
Tell is a check is active .
51,436
private function _checkEmptyFile ( $ fileName ) { if ( $ this -> _isActive ( 'checkEmptyFile' ) ) { $ msg = $ this -> _getMessage ( 'EMPTY_FILE' , $ fileName ) ; $ this -> _writeError ( 'checkEmptyFile' , $ msg ) ; } }
Check for empty PHP files .
51,437
private function _writeError ( $ check , $ message , $ lineNumber = null , $ level = null ) { if ( $ lineNumber === null ) { $ lineNumber = $ this -> lineNumber ; } if ( $ level === null ) { $ level = $ this -> _config -> getTestLevel ( $ check ) ; if ( $ level === null ) { $ level = WARNING ; } } $ this -> errorCounts [ $ level ] ++ ; $ this -> _reporter -> writeError ( $ lineNumber , $ check , $ message , $ level ) ; }
Output the error to the selected reporter .
51,438
private function _checkPhpTagsStartLine ( $ token ) { if ( $ this -> _isActive ( 'phpTagsStartLine' ) ) { if ( ! $ this -> _isLineStart ) { $ this -> _writeError ( 'phpTagsStartLine' , $ this -> _getMessage ( 'PHP_TAGS_START_LINE' ) ) ; } } }
Check that the PHP Open or Close tag is at the beginning of the line ..
51,439
private function _checkPreferQuotes ( $ token ) { if ( $ this -> _isActive ( 'preferQuotes' ) ) { $ style = $ this -> _config -> getTestProperty ( 'preferQuotes' , 'type' ) ; if ( $ style === SINGLE_QUOTE && $ token -> text === '"' ) { $ this -> _writeError ( 'preferQuotes' , $ this -> _getMessage ( "PREFER_SINGLE_QUOTES" ) ) ; } elseif ( $ style === DOUBLE_QUOTE && $ token -> text === "'" ) { $ this -> _writeError ( 'preferQuotes' , $ this -> _getMessage ( "PREFER_DOUBLE_QUOTES" ) ) ; } } }
Check the style of the quotes used .
51,440
private function _checkVariableNameLength ( $ name ) { if ( $ this -> _isActive ( 'localScopeVariableLength' ) ) { $ name = substr ( $ name , 1 ) ; if ( $ this -> _config -> isException ( 'localScopeVariableLength' , $ name ) ) { return ; } $ length = strlen ( $ name ) ; $ min = $ this -> _config -> getTestProperty ( 'localScopeVariableLength' , 'minLength' ) ; $ max = $ this -> _config -> getTestProperty ( 'localScopeVariableLength' , 'maxLength' ) ; if ( ! empty ( $ min ) && ( $ length < $ min ) ) { $ msg = $ this -> _getMessage ( 'VARIABLE_NAMING_LENGTH_SHORT' , $ name ) ; $ this -> _writeError ( 'localScopeVariableLength' , $ msg ) ; } if ( ! empty ( $ max ) && ( $ length > $ max ) ) { $ msg = $ this -> _getMessage ( 'VARIABLE_NAMING_LENGTH_LONG' , $ name ) ; $ this -> _writeError ( 'localScopeVariableLength' , $ msg ) ; } } }
Check the length of a local variable name .
51,441
private function _extractPackageName ( $ filename ) { $ filename = str_replace ( '/' , '.' , $ filename ) ; $ filename = str_replace ( '\\' , '.' , $ filename ) ; while ( strpos ( $ filename , '.' ) === 0 ) { $ filename = substr ( $ filename , 1 ) ; } if ( strlen ( $ filename ) > 4 ) { $ filename = substr ( $ filename , 0 , - 4 ) ; } $ packageName = substr ( $ filename , 0 , strrpos ( $ filename , '.' ) ) ; return $ packageName ; }
Extract a package name from the filename .
51,442
private function _getMessage ( ) { set_error_handler ( array ( $ this , '_messageErrorHandler' ) , E_ALL ) ; $ args = func_get_args ( ) ; if ( isset ( $ this -> messages [ $ args [ 0 ] ] ) ) { $ msg = $ this -> messages [ $ args [ 0 ] ] ; try { array_shift ( $ args ) ; $ formattedMsg = vsprintf ( $ msg , $ args ) ; } catch ( Exception $ e ) { $ formattedMsg = $ msg ; } set_error_handler ( array ( $ this , 'customErrorHandler' ) , E_ALL ) ; return $ formattedMsg ; } return FALSE ; }
Returns the message for the language chosen .
51,443
private function _inArray ( $ needle , $ haystack ) { foreach ( $ haystack as $ strand ) { if ( fnmatch ( $ strand , $ needle ) ) { return true ; } } return false ; }
Checks if a string is in an array but with wildcards .
51,444
protected function initXml ( ) { $ this -> document = new DomDocument ( "1.0" ) ; $ this -> root = $ this -> document -> createElement ( 'checkstyle' ) ; $ this -> root -> setAttribute ( "version" , "1.0.0" ) ; $ this -> document -> appendChild ( $ this -> root ) ; }
XML header .
51,445
protected function startNewElement ( $ fileEl ) { $ this -> currentElement = $ this -> document -> createElement ( "file" ) ; if ( substr ( $ fileEl , 0 , 2 ) === './' ) { $ fileEl = substr ( $ fileEl , 2 ) ; } $ this -> currentElement -> setAttribute ( "name" , $ fileEl ) ; }
Creates a new file element .
51,446
protected function getUrlToBeCrawled ( ) { if ( ! is_null ( $ this -> option ( 'url' ) ) ) { return $ this -> option ( 'url' ) ; } if ( config ( 'laravel-link-checker.url' ) != '' ) { return config ( 'laravel-link-checker.url' ) ; } if ( config ( 'app.url' ) != '' ) { return config ( 'app.url' ) ; } throw new Exception ( 'could not determine which url to be crawled.' ) ; }
Determine the url to be crawled .
51,447
protected function getReporter ( ) : CrawlObserver { if ( ! is_null ( $ this -> option ( 'reporter' ) ) ) { return app ( $ this -> option ( 'reporter' ) ) ; } if ( config ( 'laravel-link-checker.default_reporter' ) != '' ) { return app ( config ( 'laravel-link-checker.default_reporter' ) ) ; } throw new Exception ( 'Could not reporter the profile to be used' ) ; }
Get the reporter .
51,448
protected function crawledBadUrls ( ) : bool { return collect ( $ this -> urlsGroupedByStatusCode ) -> keys ( ) -> filter ( function ( $ statusCode ) { return ! $ this -> isSuccessOrRedirect ( $ statusCode ) ; } ) -> count ( ) > 0 ; }
Determine if the crawler saw some bad urls .
51,449
public function setIframe ( $ value ) { $ profile = ( ( bool ) $ value ? static :: PROFILE_LOW : static :: PROFILE_NORMAL ) ; return $ this -> setParameter ( 'profile' , $ profile ) ; }
Convenience method to switch iframe mode on or off . This sets the profile parameter .
51,450
protected function getBaseData ( ) { $ data = array ( ) ; $ data [ 'VPSProtocol' ] = $ this -> VPSProtocol ; $ data [ 'TxType' ] = $ this -> getTxType ( ) ; $ data [ 'Vendor' ] = $ this -> getVendor ( ) ; $ data [ 'AccountType' ] = $ this -> getAccountType ( ) ? : static :: ACCOUNT_TYPE_E ; if ( $ language = $ this -> getLanguage ( ) ) { $ language = strtoupper ( $ language ) ; list ( $ language ) = preg_split ( '/[-_]/' , $ language ) ; $ data [ 'Language' ] = $ language ; } return $ data ; }
Basic authorisation transaction type and protocol version .
51,451
protected function getAddressData ( $ type = 'Billing' ) { $ card = $ this -> getCard ( ) ; $ mapping = [ 'Firstnames' => 'FirstName' , 'Surname' => 'LastName' , 'Address1' => 'Address1' , 'Address2' => 'Address2' , 'City' => 'City' , 'PostCode' => 'Postcode' , 'State' => 'State' , 'Country' => 'Country' , 'Phone' => 'Phone' , ] ; $ data = [ ] ; foreach ( $ mapping as $ sagepayName => $ omnipayName ) { $ data [ $ sagepayName ] = call_user_func ( [ $ card , 'get' . $ type . $ omnipayName ] ) ; } if ( $ data [ 'Country' ] !== 'US' ) { $ data [ 'State' ] = '' ; } return $ data ; }
Get either the billing or the shipping address from the card object mapped to Sage Pay field names .
51,452
protected function getBillingAddressData ( array $ data = [ ] ) { $ address = $ this -> getAddressData ( 'Billing' ) ; foreach ( $ address as $ name => $ value ) { $ data [ 'Billing' . $ name ] = $ value ; } return $ data ; }
Add the billing address details to the data .
51,453
public function sendData ( $ data ) { array_walk ( $ data , function ( & $ value ) { if ( ! isset ( $ value ) ) { $ value = '' ; } } ) ; $ httpResponse = $ this -> httpClient -> request ( 'POST' , $ this -> getEndpoint ( ) , [ 'Content-Type' => 'application/x-www-form-urlencoded' , ] , http_build_query ( $ data ) ) ; $ responseData = static :: parseBodyData ( $ httpResponse ) ; return $ this -> createResponse ( $ responseData ) ; }
Send data to the remote gateway parse the result into an array then use that to instantiate the response object .
51,454
public static function parseBodyData ( ResponseInterface $ httpResponse ) { $ bodyText = ( string ) $ httpResponse -> getBody ( ) ; $ lines = preg_split ( '/[\n\r]+/' , $ bodyText ) ; $ responseData = [ ] ; foreach ( $ lines as $ line ) { $ line = explode ( '=' , $ line , 2 ) ; if ( ! empty ( $ line [ 0 ] ) ) { $ responseData [ trim ( $ line [ 0 ] ) ] = isset ( $ line [ 1 ] ) ? trim ( $ line [ 1 ] ) : '' ; } } return $ responseData ; }
The payload consists of name = > value pairs each on a separate line .
51,455
protected function filterItemName ( $ name ) { $ standardChars = '0-9a-zA-Z' ; $ allowedSpecialChars = " +'/\\&:,.-{}" ; $ pattern = '`[^' . $ standardChars . preg_quote ( $ allowedSpecialChars , '/' ) . ']`' ; $ name = trim ( substr ( preg_replace ( $ pattern , '' , $ name ) , 0 , 100 ) ) ; return $ name ; }
Filters out any characters that SagePay does not support from the item name .
51,456
protected function getItemData ( ) { $ result = '' ; $ items = $ this -> getItems ( ) ; if ( empty ( $ items ) || $ items -> all ( ) === array ( ) ) { return $ result ; } $ xml = new \ SimpleXMLElement ( '<basket/>' ) ; $ cartHasDiscounts = false ; foreach ( $ items as $ basketItem ) { if ( $ basketItem -> getPrice ( ) < 0 ) { $ cartHasDiscounts = true ; } else { $ vat = '0.00' ; if ( $ basketItem instanceof ExtendItem ) { $ vat = $ basketItem -> getVat ( ) ; } $ total = ( $ basketItem -> getQuantity ( ) * ( $ basketItem -> getPrice ( ) + $ vat ) ) ; $ item = $ xml -> addChild ( 'item' ) ; $ item -> description = $ this -> filterItemName ( $ basketItem -> getName ( ) ) ; $ item -> addChild ( 'quantity' , $ basketItem -> getQuantity ( ) ) ; $ item -> addChild ( 'unitNetAmount' , $ basketItem -> getPrice ( ) ) ; $ item -> addChild ( 'unitTaxAmount' , $ vat ) ; $ item -> addChild ( 'unitGrossAmount' , $ basketItem -> getPrice ( ) + $ vat ) ; $ item -> addChild ( 'totalGrossAmount' , $ total ) ; } } if ( $ cartHasDiscounts ) { $ discounts = $ xml -> addChild ( 'discounts' ) ; foreach ( $ items as $ discountItem ) { if ( $ discountItem -> getPrice ( ) < 0 ) { $ discount = $ discounts -> addChild ( 'discount' ) ; $ discount -> addChild ( 'fixed' , ( $ discountItem -> getPrice ( ) * $ discountItem -> getQuantity ( ) ) * - 1 ) ; $ discount -> description = $ this -> filterDiscountName ( $ discountItem -> getName ( ) ) ; } } } $ xmlString = $ xml -> asXML ( ) ; if ( $ xmlString ) { $ result = $ xmlString ; } return $ result ; }
Get an XML representation of the current cart items
51,457
protected function getItemDataNonXML ( ) { $ result = '' ; $ items = $ this -> getItems ( ) ; $ count = 0 ; foreach ( $ items as $ basketItem ) { $ description = $ this -> filterNonXmlItemName ( $ basketItem -> getName ( ) ) ; $ vat = '0.00' ; if ( $ basketItem instanceof ExtendItem ) { $ vat = $ basketItem -> getVat ( ) ; if ( ! is_null ( $ basketItem -> getProductCode ( ) ) ) { $ description = '[' . $ basketItem -> getProductCode ( ) . ']' . $ description ; } } $ lineTotal = ( $ basketItem -> getQuantity ( ) * ( $ basketItem -> getPrice ( ) + $ vat ) ) ; $ result .= ':' . $ description . ':' . $ basketItem -> getQuantity ( ) . ':' . number_format ( $ basketItem -> getPrice ( ) , 2 , '.' , '' ) . ':' . $ vat . ':' . number_format ( $ basketItem -> getPrice ( ) + $ vat , 2 , '.' , '' ) . ':' . number_format ( $ lineTotal , 2 , '.' , '' ) ; $ count ++ ; } $ result = $ count . $ result ; return $ result ; }
Generate Basket string in the older non - XML format This is called if useOldBasketFormat is set to true in the gateway config
51,458
public function setTransactionReference ( $ value ) { $ reference = json_decode ( $ value , true ) ; if ( json_last_error ( ) === 0 ) { if ( isset ( $ reference [ 'VendorTxCode' ] ) ) { $ this -> setRelatedTransactionId ( $ reference [ 'VendorTxCode' ] ) ; } if ( isset ( $ reference [ 'VPSTxId' ] ) ) { $ this -> setVpsTxId ( $ reference [ 'VPSTxId' ] ) ; } if ( isset ( $ reference [ 'SecurityKey' ] ) ) { $ this -> setSecurityKey ( $ reference [ 'SecurityKey' ] ) ; } if ( isset ( $ reference [ 'TxAuthNo' ] ) ) { $ this -> setTxAuthNo ( $ reference [ 'TxAuthNo' ] ) ; } } return parent :: setTransactionReference ( $ value ) ; }
A JSON transactionReference passed in is split into its component parts .
51,459
protected function getBaseAuthorizeData ( ) { $ this -> validate ( 'amount' , 'card' , 'transactionId' ) ; $ data = $ this -> getBaseData ( ) ; $ data [ 'Description' ] = $ this -> getDescription ( ) ; $ data [ 'Amount' ] = $ this -> getAmount ( ) ; $ data [ 'Currency' ] = $ this -> getCurrency ( ) ; $ data [ 'VendorData' ] = $ this -> getVendorData ( ) ; $ data [ 'VendorTxCode' ] = $ this -> getTransactionId ( ) ; $ data [ 'ClientIPAddress' ] = $ this -> getClientIp ( ) ; $ data [ 'ApplyAVSCV2' ] = $ this -> getApplyAVSCV2 ( ) ? : static :: APPLY_AVSCV2_DEFAULT ; $ data [ 'Apply3DSecure' ] = $ this -> getApply3DSecure ( ) ? : static :: APPLY_3DSECURE_APPLY ; if ( $ this -> getReferrerId ( ) ) { $ data [ 'ReferrerID' ] = $ this -> getReferrerId ( ) ; } $ data = $ this -> getBillingAddressData ( $ data ) ; $ data = $ this -> getDeliveryAddressData ( $ data ) ; $ card = $ this -> getCard ( ) ; if ( $ card -> getEmail ( ) ) { $ data [ 'CustomerEMail' ] = $ card -> getEmail ( ) ; } if ( ( bool ) $ this -> getUseOldBasketFormat ( ) ) { $ basket = $ this -> getItemDataNonXML ( ) ; if ( ! empty ( $ basket ) ) { $ data [ 'Basket' ] = $ basket ; } } else { $ basketXML = $ this -> getItemData ( ) ; if ( ! empty ( $ basketXML ) ) { $ data [ 'BasketXML' ] = $ basketXML ; } } $ surchargeXml = $ this -> getSurchargeXml ( ) ; if ( $ surchargeXml ) { $ data [ 'surchargeXml' ] = $ surchargeXml ; } return $ data ; }
The required fields concerning what is being authorised and who it is being authorised for .
51,460
public function getTokenData ( $ data = array ( ) ) { if ( $ this -> getToken ( ) || $ this -> getCardReference ( ) ) { $ data [ 'Token' ] = $ this -> getToken ( ) ? : $ this -> getCardReference ( ) ; $ storeToken = $ this -> getStoreToken ( ) ; if ( $ storeToken === null ) { if ( ( bool ) $ this -> getCardReference ( ) ) { $ data [ 'StoreToken' ] = static :: STORE_TOKEN_YES ; } } elseif ( $ storeToken !== static :: STORE_TOKEN_YES && $ storeToken !== static :: STORE_TOKEN_NO ) { $ data [ 'StoreToken' ] = ( bool ) $ storeToken ? static :: STORE_TOKEN_YES : static :: STORE_TOKEN_NO ; } else { $ data [ 'StoreToken' ] = $ storeToken ; } } return $ data ; }
If a token or cardReference is being used then include the details of the token in the data .
51,461
public function getCardData ( $ data = array ( ) ) { $ this -> getCard ( ) -> validate ( ) ; if ( $ this -> getCardholderName ( ) ) { $ data [ 'CardHolder' ] = $ this -> getCardholderName ( ) ; } else { $ data [ 'CardHolder' ] = $ this -> getCard ( ) -> getName ( ) ; } if ( ! $ this -> getToken ( ) ) { $ data [ 'CardNumber' ] = $ this -> getCard ( ) -> getNumber ( ) ; } $ data [ 'ExpiryDate' ] = $ this -> getCard ( ) -> getExpiryDate ( 'my' ) ; $ data [ 'CardType' ] = $ this -> getCardBrand ( ) ; if ( $ this -> getCard ( ) -> getStartMonth ( ) and $ this -> getCard ( ) -> getStartYear ( ) ) { $ data [ 'StartDate' ] = $ this -> getCard ( ) -> getStartDate ( 'my' ) ; } if ( $ this -> getCard ( ) -> getIssueNumber ( ) ) { $ data [ 'IssueNumber' ] = $ this -> getCard ( ) -> getIssueNumber ( ) ; } $ createCard = $ this -> getCreateToken ( ) ? : $ this -> getCreateCard ( ) ; if ( $ createCard !== null ) { $ data [ 'CreateToken' ] = $ createCard ? static :: CREATE_TOKEN_YES : static :: CREATE_TOKEN_NO ; } if ( $ this -> getCard ( ) -> getCvv ( ) !== null ) { $ data [ 'CV2' ] = $ this -> getCard ( ) -> getCvv ( ) ; } return $ data ; }
If a credit card is being used then include the details of the card in the data .
51,462
public function getData ( ) { $ data = $ this -> getBaseAuthorizeData ( ) ; if ( $ this -> getToken ( ) || $ this -> getCardReference ( ) ) { $ data = $ this -> getTokenData ( $ data ) ; } else { $ data = $ this -> getCardData ( $ data ) ; } if ( $ this -> getCard ( ) -> getCvv ( ) !== null ) { $ data [ 'CV2' ] = $ this -> getCard ( ) -> getCvv ( ) ; } return $ data ; }
Add the credit card or token details to the data .
51,463
public function sendResponse ( $ status , $ nextUrl , $ detail = null ) { $ message = "Status=$status\r\nRedirectUrl=$nextUrl" ; if ( null !== $ detail ) { $ message .= "\r\nStatusDetail=" . $ detail ; } $ this -> exitWith ( $ message ) ; }
Respond to SagePay confirming or rejecting the payment .
51,464
public function getData ( ) { $ this -> validate ( 'currency' , 'description' , 'encryptionKey' , 'returnUrl' ) ; return [ 'VPSProtocol' => $ this -> VPSProtocol , 'TxType' => $ this -> getTxType ( ) , 'Vendor' => $ this -> getVendor ( ) , 'Crypt' => $ this -> generateCrypt ( $ this -> getCryptData ( ) ) , 'TestMode' => $ this -> getTestMode ( ) , ] ; }
Get the full set of Sage Pay Form data most of which is encrypted . TxType is only PAYMENT DEFERRED or AUTHENTICATE
51,465
public function generateCrypt ( array $ data ) { array_walk ( $ data , function ( & $ value ) { if ( ! isset ( $ value ) ) { $ value = '' ; } } ) ; $ disableUtf8Decode = ( bool ) $ this -> getDisableUtf8Decode ( ) ; $ query = [ ] ; foreach ( $ data as $ name => $ value ) { $ query [ ] = $ name . '=' . ( $ disableUtf8Decode ? $ value : utf8_decode ( $ value ) ) ; } $ query = implode ( '&' , $ query ) ; $ key = $ this -> getEncryptionKey ( ) ; $ crypt = openssl_encrypt ( $ query , 'aes-128-cbc' , $ key , OPENSSL_RAW_DATA , $ key ) ; return '@' . strtoupper ( bin2hex ( $ crypt ) ) ; }
Generate the crypt field from the source data .
51,466
public function getData ( ) { $ crypt = $ this -> getCrypt ( ) ? : $ this -> httpRequest -> query -> get ( 'crypt' ) ; if ( empty ( $ crypt ) || ! is_string ( $ crypt ) || substr ( $ crypt , 0 , 1 ) !== '@' ) { throw new InvalidResponseException ( 'Missing or invalid "crypt" parameter' ) ; } $ hexString = substr ( $ crypt , 1 ) ; if ( ! preg_match ( '/^[0-9a-f]+$/i' , $ hexString ) ) { throw new InvalidResponseException ( 'Invalid "crypt" parameter; not hexadecimal' ) ; } $ queryString = openssl_decrypt ( hex2bin ( $ hexString ) , 'aes-128-cbc' , $ this -> getEncryptionKey ( ) , OPENSSL_RAW_DATA , $ this -> getEncryptionKey ( ) ) ; parse_str ( $ queryString , $ data ) ; return ( $ data ) ; }
Data will be encrypted as a query parameter .
51,467
public function buildSignature ( ) { $ VPSTxId = $ this -> getVPSTxId ( ) ; if ( $ this -> getTxType ( ) === Response :: TXTYPE_TOKEN && $ this -> getStatus ( ) === Response :: SAGEPAY_STATUS_OK ) { $ VPSTxId = str_replace ( [ '{' , '}' ] , '' , $ VPSTxId ) ; } $ signatureData = array ( $ VPSTxId , $ this -> getTransactionId ( ) , $ this -> getStatus ( ) , $ this -> getTxAuthNo ( ) , strtolower ( $ this -> getVendor ( ) ) , $ this -> getAVSCV2 ( ) , ( $ this -> getTxType ( ) === Response :: TXTYPE_TOKEN ? $ this -> getToken ( ) : '' ) , $ this -> getSecurityKey ( ) , ) ; if ( $ this -> getTxType ( ) !== Response :: TXTYPE_TOKEN || $ this -> getStatus ( ) !== Response :: SAGEPAY_STATUS_OK ) { $ signatureData = array_merge ( $ signatureData , array ( $ this -> getAddressResult ( ) , $ this -> getPostCodeResult ( ) , $ this -> getCV2Result ( ) , $ this -> getGiftAid ( ) , $ this -> get3DSecureStatus ( ) , $ this -> getCAVV ( ) , $ this -> getAddressStatus ( ) , $ this -> getPayerStatus ( ) , $ this -> getCardType ( ) , $ this -> getLast4Digits ( ) , $ this -> getDeclineCode ( ) , $ this -> getExpiryDate ( ) , $ this -> getFraudResponse ( ) , $ this -> getBankAuthCode ( ) , ) ) ; } return md5 ( implode ( '' , $ signatureData ) ) ; }
Create the signature calculated from the POST data and the saved SecurityKey . This signature is lower case .
51,468
public function getTransactionStatus ( ) { if ( ! $ this -> isValid ( ) ) { return static :: STATUS_FAILED ; } $ status = $ this -> getStatus ( ) ; if ( $ status === Response :: SAGEPAY_STATUS_OK || $ status === Response :: SAGEPAY_STATUS_OK_REPEATED || $ status === Response :: SAGEPAY_STATUS_AUTHENTICATED || $ status === Response :: SAGEPAY_STATUS_REGISTERED ) { return static :: STATUS_COMPLETED ; } if ( $ status === Response :: SAGEPAY_STATUS_PENDING ) { return static :: STATUS_PENDING ; } return static :: STATUS_FAILED ; }
Was the transaction successful?
51,469
public function getTransactionReference ( ) { $ reference = [ ] ; foreach ( [ 'TxAuthNo' , 'VPSTxId' ] as $ key ) { $ value = $ this -> getDataItem ( $ key ) ; if ( $ value !== null ) { $ reference [ $ key ] = $ value ; } } if ( empty ( $ reference ) ) { return ; } $ reference [ 'SecurityKey' ] = $ this -> getSecurityKey ( ) ; $ reference [ 'VendorTxCode' ] = $ this -> getTransactionId ( ) ; ksort ( $ reference ) ; return json_encode ( $ reference ) ; }
Gateway Reference .
51,470
public function getData ( ) { if ( ! $ this -> getReturnUrl ( ) ) { $ this -> validate ( 'notifyUrl' ) ; } $ data = $ this -> getBaseAuthorizeData ( ) ; $ data = $ this -> getTokenData ( $ data ) ; $ data [ 'NotificationURL' ] = $ this -> getNotifyUrl ( ) ? : $ this -> getReturnUrl ( ) ; $ profile = strtoupper ( $ this -> getProfile ( ) ) ; if ( $ profile === static :: PROFILE_NORMAL || $ profile === static :: PROFILE_LOW ) { $ data [ 'Profile' ] = $ this -> getProfile ( ) ; } $ createCard = $ this -> getCreateToken ( ) ? : $ this -> getCreateCard ( ) ; if ( $ createCard !== null ) { $ data [ 'CreateToken' ] = $ createCard ? static :: CREATE_TOKEN_YES : static :: CREATE_TOKEN_NO ; } return $ data ; }
Add the optional token details to the base data . The returnUrl is supported for legacy applications not using the notifyUrl .
51,471
public function getResponseBody ( $ status , $ nextUrl , $ detail = null ) { $ body = [ 'Status=' . $ status , 'RedirectUrl=' . $ nextUrl , ] ; if ( $ detail !== null ) { $ body [ ] = 'StatusDetail=' . $ detail ; } return implode ( static :: LINE_SEP , $ body ) ; }
Construct the response body .
51,472
public function sendResponse ( $ status , $ nextUrl , $ detail = null ) { $ message = $ this -> getResponseBody ( $ status , $ nextUrl , $ detail ) ; echo $ message ; if ( ( bool ) $ this -> getExitOnResponse ( ) ) { exit ; } }
Respond to SagePay confirming or rejecting the notification .
51,473
public function getData ( ) { $ signature = $ this -> getSignature ( ) ; $ VPSSignature = strtolower ( $ this -> httpRequest -> request -> get ( 'VPSSignature' ) ) ; if ( $ VPSSignature !== $ signature ) { throw new InvalidResponseException ; } return $ this -> httpRequest -> request -> all ( ) ; }
Get the POSTed data checking that the signature is valid .
51,474
public function getExpiryDate ( $ format = null ) { $ expiryDate = $ this -> getDataItem ( 'ExpiryDate' ) ; if ( $ format === null || $ expiryDate === null ) { return $ expiryDate ; } else { return gmdate ( $ format , gmmktime ( 0 , 0 , 0 , $ this -> getExpiryMonth ( ) , 1 , $ this -> getExpiryYear ( ) ) ) ; } }
Raw expiry date for the card MMYY format by default . The expiry date is available for Sage Pay Direct responses even if the remaining card details are not . Also supports custom formats .
51,475
public function getExpiryYear ( ) { $ expiryDate = $ this -> getDataItem ( 'ExpiryDate' ) ; if ( ! empty ( $ expiryDate ) ) { $ dateTime = \ DateTime :: createFromFormat ( 'y' , substr ( $ expiryDate , 2 , 2 ) ) ; return ( int ) $ dateTime -> format ( 'Y' ) ; } }
Get the card expiry year .
51,476
protected function addBladeDirectives ( ) { $ this -> app -> afterResolving ( 'blade.compiler' , function ( BladeCompiler $ bladeCompiler ) { $ bladeCompiler -> directive ( 'meta' , function ( $ arguments ) { return "<?php echo Meta::tag($arguments); ?>" ; } ) ; $ bladeCompiler -> directive ( 'metas' , function ( $ arguments ) { return "<?php echo Meta::tags($arguments); ?>" ; } ) ; } ) ; }
Register blade directives
51,477
public function customersNotesCreate ( $ note , $ site = null ) { if ( empty ( $ note [ 'customer' ] [ 'id' ] ) && empty ( $ note [ 'customer' ] [ 'externalId' ] ) ) { throw new \ InvalidArgumentException ( 'Customer identifier must be set' ) ; } return $ this -> client -> makeRequest ( '/customers/notes/create' , "POST" , $ this -> fillSite ( $ site , [ 'note' => json_encode ( $ note ) ] ) ) ; }
Create customer note
51,478
public function costsCreate ( array $ cost , $ site = null ) { if ( ! count ( $ cost ) ) { throw new \ InvalidArgumentException ( 'Parameter `cost` must contains a data' ) ; } return $ this -> client -> makeRequest ( '/costs/create' , "POST" , $ this -> fillSite ( $ site , [ 'cost' => json_encode ( $ cost ) ] ) ) ; }
Create a cost
51,479
public function costsDelete ( array $ ids ) { if ( ! count ( $ ids ) ) { throw new \ InvalidArgumentException ( 'Parameter `ids` must contains a data' ) ; } return $ this -> client -> makeRequest ( '/costs/delete' , "POST" , [ 'ids' => json_encode ( $ ids ) ] ) ; }
Delete costs set
51,480
public function costsEdit ( array $ cost , $ site = null ) { if ( ! count ( $ cost ) ) { throw new \ InvalidArgumentException ( 'Parameter `cost` must contains a data' ) ; } return $ this -> client -> makeRequest ( sprintf ( '/costs/%s/edit' , $ cost [ 'id' ] ) , "POST" , $ this -> fillSite ( $ site , [ 'cost' => json_encode ( $ cost ) ] ) ) ; }
Edit a cost
51,481
public function costsDeleteById ( $ id ) { if ( ! empty ( $ id ) ) { throw new \ InvalidArgumentException ( 'Parameter `id` must contains a data' ) ; } return $ this -> client -> makeRequest ( sprintf ( '/costs/%s/delete' , $ id ) , "POST" ) ; }
Delete cost by id
51,482
public function deliveryShipmentsCreate ( array $ shipment , $ deliveryType , $ site = null ) { if ( ! count ( $ shipment ) ) { throw new \ InvalidArgumentException ( 'Parameter `shipment` must contains a data' ) ; } return $ this -> client -> makeRequest ( '/delivery/shipments/create' , "POST" , $ this -> fillSite ( $ site , [ 'deliveryShipment' => json_encode ( $ shipment ) , 'deliveryType' => $ deliveryType ] ) ) ; }
Create delivery shipment
51,483
public function deliveryShipmentsEdit ( array $ shipment , $ site = null ) { if ( ! count ( $ shipment ) ) { throw new \ InvalidArgumentException ( 'Parameter `shipment` must contains a data' ) ; } if ( empty ( $ shipment [ 'id' ] ) ) { throw new \ InvalidArgumentException ( 'Parameter `shipment` must contains an `id` field' ) ; } return $ this -> client -> makeRequest ( sprintf ( "/delivery/shipments/%s/edit" , $ shipment [ 'id' ] ) , "POST" , $ this -> fillSite ( $ site , [ 'deliveryShipment' => json_encode ( $ shipment ) ] ) ) ; }
Edit delivery shipment
51,484
public function integrationModulesGet ( $ code ) { if ( empty ( $ code ) ) { throw new \ InvalidArgumentException ( 'Parameter `code` must be set' ) ; } return $ this -> client -> makeRequest ( sprintf ( '/integration-modules/%s' , $ code ) , "GET" ) ; }
Get module configuration
51,485
public function integrationModulesEdit ( array $ configuration ) { if ( ! count ( $ configuration ) || empty ( $ configuration [ 'code' ] ) ) { throw new \ InvalidArgumentException ( 'Parameter `configuration` must contains a data & configuration `code` must be set' ) ; } return $ this -> client -> makeRequest ( sprintf ( '/integration-modules/%s/edit' , $ configuration [ 'code' ] ) , "POST" , [ 'integrationModule' => json_encode ( $ configuration ) ] ) ; }
Edit module configuration
51,486
public function telephonySettingsEdit ( $ code , $ clientId , $ active = false , $ name = false , $ makeCallUrl = false , $ image = false , $ additionalCodes = [ ] , $ externalPhones = [ ] , $ allowEdit = false , $ inputEventSupported = false , $ outputEventSupported = false , $ hangupEventSupported = false , $ changeUserStatusUrl = false ) { if ( ! isset ( $ code ) ) { throw new \ InvalidArgumentException ( 'Code must be set' ) ; } $ parameters [ 'code' ] = $ code ; if ( ! isset ( $ clientId ) ) { throw new \ InvalidArgumentException ( 'client id must be set' ) ; } $ parameters [ 'clientId' ] = $ clientId ; if ( ! isset ( $ active ) ) { $ parameters [ 'active' ] = false ; } else { $ parameters [ 'active' ] = $ active ; } if ( ! isset ( $ name ) ) { throw new \ InvalidArgumentException ( 'name must be set' ) ; } if ( isset ( $ name ) ) { $ parameters [ 'name' ] = $ name ; } if ( isset ( $ makeCallUrl ) ) { $ parameters [ 'makeCallUrl' ] = $ makeCallUrl ; } if ( isset ( $ image ) ) { $ parameters [ 'image' ] = $ image ; } if ( isset ( $ additionalCodes ) ) { $ parameters [ 'additionalCodes' ] = $ additionalCodes ; } if ( isset ( $ externalPhones ) ) { $ parameters [ 'externalPhones' ] = $ externalPhones ; } if ( isset ( $ allowEdit ) ) { $ parameters [ 'allowEdit' ] = $ allowEdit ; } if ( isset ( $ inputEventSupported ) ) { $ parameters [ 'inputEventSupported' ] = $ inputEventSupported ; } if ( isset ( $ outputEventSupported ) ) { $ parameters [ 'outputEventSupported' ] = $ outputEventSupported ; } if ( isset ( $ hangupEventSupported ) ) { $ parameters [ 'hangupEventSupported' ] = $ hangupEventSupported ; } if ( isset ( $ changeUserStatusUrl ) ) { $ parameters [ 'changeUserStatusUrl' ] = $ changeUserStatusUrl ; } return $ this -> client -> makeRequest ( "/telephony/setting/$code/edit" , "POST" , [ 'configuration' => json_encode ( $ parameters ) ] ) ; }
Edit telephony settings
51,487
public function ordersPacksCreate ( array $ pack , $ site = null ) { if ( ! count ( $ pack ) ) { throw new \ InvalidArgumentException ( 'Parameter `pack` must contains a data' ) ; } return $ this -> client -> makeRequest ( '/orders/packs/create' , "POST" , $ this -> fillSite ( $ site , [ 'pack' => json_encode ( $ pack ) ] ) ) ; }
Create orders assembly
51,488
public function ordersPacksDelete ( $ id ) { if ( empty ( $ id ) ) { throw new \ InvalidArgumentException ( 'Parameter `id` must be set' ) ; } return $ this -> client -> makeRequest ( sprintf ( '/orders/packs/%s/delete' , $ id ) , "POST" ) ; }
Delete orders assembly by id
51,489
public function ordersPacksEdit ( array $ pack , $ site = null ) { if ( ! count ( $ pack ) || empty ( $ pack [ 'id' ] ) ) { throw new \ InvalidArgumentException ( 'Parameter `pack` must contains a data & pack `id` must be set' ) ; } return $ this -> client -> makeRequest ( sprintf ( '/orders/packs/%s/edit' , $ pack [ 'id' ] ) , "POST" , $ this -> fillSite ( $ site , [ 'pack' => json_encode ( $ pack ) ] ) ) ; }
Edit orders assembly
51,490
public function usersList ( array $ filter = [ ] , $ page = null , $ limit = null ) { $ parameters = [ ] ; if ( count ( $ filter ) ) { $ parameters [ 'filter' ] = $ filter ; } if ( null !== $ page ) { $ parameters [ 'page' ] = ( int ) $ page ; } if ( null !== $ limit ) { $ parameters [ 'limit' ] = ( int ) $ limit ; } return $ this -> client -> makeRequest ( '/users' , "GET" , $ parameters ) ; }
Returns users list
51,491
public function usersStatus ( $ id , $ status ) { $ statuses = [ "free" , "busy" , "dinner" , "break" ] ; if ( empty ( $ status ) || ! in_array ( $ status , $ statuses ) ) { throw new \ InvalidArgumentException ( 'Parameter `status` must be not empty & must be equal one of these values: free|busy|dinner|break' ) ; } return $ this -> client -> makeRequest ( "/users/$id/status" , "POST" , [ 'status' => $ status ] ) ; }
Change user status
51,492
public function customersUpload ( array $ customers , $ site = null ) { if ( ! count ( $ customers ) ) { throw new \ InvalidArgumentException ( 'Parameter `customers` must contains array of the customers' ) ; } return $ this -> client -> makeRequest ( '/customers/upload' , "POST" , $ this -> fillSite ( $ site , [ 'customers' => json_encode ( $ customers ) ] ) ) ; }
Upload array of the customers
51,493
public function customersEdit ( array $ customer , $ by = 'externalId' , $ site = null ) { if ( ! count ( $ customer ) ) { throw new \ InvalidArgumentException ( 'Parameter `customer` must contains a data' ) ; } $ this -> checkIdParameter ( $ by ) ; if ( ! array_key_exists ( $ by , $ customer ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Customer array must contain the "%s" parameter.' , $ by ) ) ; } return $ this -> client -> makeRequest ( sprintf ( '/customers/%s/edit' , $ customer [ $ by ] ) , "POST" , $ this -> fillSite ( $ site , [ 'customer' => json_encode ( $ customer ) , 'by' => $ by ] ) ) ; }
Edit a customer
51,494
public function ordersStatuses ( array $ ids = [ ] , array $ externalIds = [ ] ) { $ parameters = [ ] ; if ( count ( $ ids ) ) { $ parameters [ 'ids' ] = $ ids ; } if ( count ( $ externalIds ) ) { $ parameters [ 'externalIds' ] = $ externalIds ; } return $ this -> client -> makeRequest ( '/orders/statuses' , "GET" , $ parameters ) ; }
Returns statuses of the orders
51,495
public function ordersUpload ( array $ orders , $ site = null ) { if ( ! count ( $ orders ) ) { throw new \ InvalidArgumentException ( 'Parameter `orders` must contains array of the orders' ) ; } return $ this -> client -> makeRequest ( '/orders/upload' , "POST" , $ this -> fillSite ( $ site , [ 'orders' => json_encode ( $ orders ) ] ) ) ; }
Upload array of the orders
51,496
public function ordersGet ( $ id , $ by = 'externalId' , $ site = null ) { $ this -> checkIdParameter ( $ by ) ; return $ this -> client -> makeRequest ( "/orders/$id" , "GET" , $ this -> fillSite ( $ site , [ 'by' => $ by ] ) ) ; }
Get order by id or externalId
51,497
public function ordersEdit ( array $ order , $ by = 'externalId' , $ site = null ) { if ( ! count ( $ order ) ) { throw new \ InvalidArgumentException ( 'Parameter `order` must contains a data' ) ; } $ this -> checkIdParameter ( $ by ) ; if ( ! array_key_exists ( $ by , $ order ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Order array must contain the "%s" parameter.' , $ by ) ) ; } return $ this -> client -> makeRequest ( sprintf ( '/orders/%s/edit' , $ order [ $ by ] ) , "POST" , $ this -> fillSite ( $ site , [ 'order' => json_encode ( $ order ) , 'by' => $ by ] ) ) ; }
Edit an order
51,498
public function telephonyCallManager ( $ phone , $ details ) { if ( ! isset ( $ phone ) ) { throw new \ InvalidArgumentException ( 'Phone number must be set' ) ; } $ parameters [ 'phone' ] = $ phone ; $ parameters [ 'details' ] = isset ( $ details ) ? $ details : 0 ; return $ this -> client -> makeRequest ( '/telephony/manager' , "GET" , $ parameters ) ; }
Get call manager
51,499
public function customFieldsCreate ( $ entity , $ customField ) { if ( ! count ( $ customField ) || empty ( $ customField [ 'code' ] ) || empty ( $ customField [ 'name' ] ) || empty ( $ customField [ 'type' ] ) ) { throw new \ InvalidArgumentException ( 'Parameter `customField` must contain a data & fields `code`, `name` & `type` must be set' ) ; } if ( empty ( $ entity ) || ! in_array ( $ entity , [ 'customer' , 'order' ] ) ) { throw new \ InvalidArgumentException ( 'Parameter `entity` must contain a data & value must be `order` or `customer`' ) ; } return $ this -> client -> makeRequest ( "/custom-fields/$entity/create" , "POST" , [ 'customField' => json_encode ( $ customField ) ] ) ; }
Create custom field