idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
51,300
|
public function getDocument ( $ input ) { $ nodeMap = new JsonObject ( ) ; $ nodeMap -> { '-' . JsonLD :: DEFAULT_GRAPH } = new JsonObject ( ) ; $ this -> generateNodeMap ( $ nodeMap , $ input ) ; $ nodes = array ( ) ; if ( null === $ this -> documentFactory ) { $ this -> documentFactory = new DefaultDocumentFactory ( ) ; } $ document = $ this -> documentFactory -> createDocument ( $ this -> baseIri ) ; foreach ( $ nodeMap as $ graphName => & $ nodes ) { $ graphName = substr ( $ graphName , 1 ) ; if ( JsonLD :: DEFAULT_GRAPH === $ graphName ) { $ graph = $ document -> getGraph ( ) ; } else { $ graph = $ document -> createGraph ( $ graphName ) ; } foreach ( $ nodes as $ id => & $ item ) { $ node = $ graph -> createNode ( $ item -> { '@id' } , true ) ; unset ( $ item -> { '@id' } ) ; if ( property_exists ( $ item , '@type' ) ) { foreach ( $ item -> { '@type' } as $ type ) { $ node -> addType ( $ graph -> createNode ( $ type ) , true ) ; } unset ( $ item -> { '@type' } ) ; } foreach ( $ item as $ property => $ values ) { foreach ( $ values as $ value ) { if ( property_exists ( $ value , '@value' ) ) { $ node -> addPropertyValue ( $ property , Value :: fromJsonLd ( $ value ) ) ; } elseif ( property_exists ( $ value , '@id' ) ) { $ node -> addPropertyValue ( $ property , $ graph -> createNode ( $ value -> { '@id' } , true ) ) ; } else { throw new \ Exception ( 'Lists are not supported by getDocument() yet' ) ; } } } } } unset ( $ nodeMap ) ; return $ document ; }
|
Parses a JSON - LD document and returns it as a Document
|
51,301
|
private function expandValue ( $ value , $ activectx , $ activeprty ) { $ def = $ this -> getPropertyDefinition ( $ activectx , $ activeprty ) ; $ result = new JsonObject ( ) ; if ( '@id' === $ def [ '@type' ] ) { $ result -> { '@id' } = $ this -> expandIri ( $ value , $ activectx , true ) ; } elseif ( '@vocab' === $ def [ '@type' ] ) { $ result -> { '@id' } = $ this -> expandIri ( $ value , $ activectx , true , true ) ; } else { $ result -> { '@value' } = $ value ; if ( isset ( $ def [ '@type' ] ) ) { $ result -> { '@type' } = $ def [ '@type' ] ; } elseif ( isset ( $ def [ '@language' ] ) && is_string ( $ result -> { '@value' } ) ) { $ result -> { '@language' } = $ def [ '@language' ] ; } } return $ result ; }
|
Expands a scalar value
|
51,302
|
private function compactValue ( $ value , $ definition , $ activectx , $ inversectx ) { if ( '@index' === $ definition [ '@container' ] ) { unset ( $ value -> { '@index' } ) ; } $ numProperties = count ( get_object_vars ( $ value ) ) ; if ( property_exists ( $ value , '@id' ) ) { if ( 1 === $ numProperties ) { if ( '@id' === $ definition [ '@type' ] ) { return $ this -> compactIri ( $ value -> { '@id' } , $ activectx , $ inversectx ) ; } if ( '@vocab' === $ definition [ '@type' ] ) { return $ this -> compactIri ( $ value -> { '@id' } , $ activectx , $ inversectx , null , true ) ; } } return $ value ; } $ criterion = ( isset ( $ value -> { '@type' } ) ) ? '@type' : null ; $ criterion = ( isset ( $ value -> { '@language' } ) ) ? '@language' : $ criterion ; if ( null !== $ criterion ) { if ( ( 2 === $ numProperties ) && ( $ value -> { $ criterion } === $ definition [ $ criterion ] ) ) { return $ value -> { '@value' } ; } return $ value ; } if ( is_string ( $ value -> { '@value' } ) && ( null !== $ definition [ '@language' ] ) ) { return $ value ; } return ( 1 === $ numProperties ) ? $ value -> { '@value' } : $ value ; }
|
Compacts a value
|
51,303
|
private static function subtreeEquals ( $ a , $ b ) { if ( gettype ( $ a ) !== gettype ( $ b ) ) { return false ; } if ( is_scalar ( $ a ) ) { return ( $ a === $ b ) ; } if ( is_array ( $ a ) ) { $ len = count ( $ a ) ; if ( $ len !== count ( $ b ) ) { return false ; } for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { if ( false === self :: subtreeEquals ( $ a [ $ i ] , $ b [ $ i ] ) ) { return false ; } } return true ; } if ( ! property_exists ( $ a , '@id' ) && ! property_exists ( $ a , '@value' ) && ! property_exists ( $ a , '@list' ) ) { return false ; } $ properties = array_keys ( get_object_vars ( $ a ) ) ; if ( count ( $ properties ) !== count ( get_object_vars ( $ b ) ) ) { return false ; } foreach ( $ properties as $ property ) { if ( ( false === property_exists ( $ b , $ property ) ) || ( false === self :: subtreeEquals ( $ a -> { $ property } , $ b -> { $ property } ) ) ) { return false ; } } return true ; }
|
Verifies whether two JSON - LD subtrees are equal not
|
51,304
|
private function getValueProfile ( JsonObject $ value , $ inversectx ) { $ valueProfile = array ( '@container' => '@set' , 'typeLang' => '@type' , 'typeLangValue' => '@id' ) ; if ( property_exists ( $ value , '@index' ) ) { $ valueProfile [ '@container' ] = '@index' ; } if ( property_exists ( $ value , '@id' ) ) { if ( isset ( $ inversectx [ $ value -> { '@id' } ] [ 'term' ] ) ) { $ valueProfile [ 'typeLangValue' ] = '@vocab' ; } else { $ valueProfile [ 'typeLangValue' ] = '@id' ; } return $ valueProfile ; } if ( property_exists ( $ value , '@value' ) ) { if ( property_exists ( $ value , '@type' ) ) { $ valueProfile [ 'typeLang' ] = '@type' ; $ valueProfile [ 'typeLangValue' ] = $ value -> { '@type' } ; } elseif ( property_exists ( $ value , '@language' ) ) { $ valueProfile [ 'typeLang' ] = '@language' ; $ valueProfile [ 'typeLangValue' ] = $ value -> { '@language' } ; if ( false === property_exists ( $ value , '@index' ) ) { $ valueProfile [ '@container' ] = '@language' ; } } else { $ valueProfile [ 'typeLang' ] = '@language' ; $ valueProfile [ 'typeLangValue' ] = '@null' ; } return $ valueProfile ; } if ( property_exists ( $ value , '@list' ) ) { $ len = count ( $ value -> { '@list' } ) ; if ( $ len > 0 ) { $ valueProfile = $ this -> getValueProfile ( $ value -> { '@list' } [ 0 ] , $ inversectx ) ; } if ( false === property_exists ( $ value , '@index' ) ) { $ valueProfile [ '@container' ] = '@list' ; } for ( $ i = $ len - 1 ; $ i > 0 ; $ i -- ) { $ profile = $ this -> getValueProfile ( $ value -> { '@list' } [ $ i ] , $ inversectx ) ; if ( ( $ valueProfile [ 'typeLang' ] !== $ profile [ 'typeLang' ] ) || ( $ valueProfile [ 'typeLangValue' ] !== $ profile [ 'typeLangValue' ] ) ) { $ valueProfile [ 'typeLang' ] = null ; $ valueProfile [ 'typeLangValue' ] = null ; return $ valueProfile ; } } } return $ valueProfile ; }
|
Calculates a value profile
|
51,305
|
private function getPropertyDefinition ( $ activectx , $ property , $ only = null ) { $ result = array ( '@reverse' => false , '@type' => null , '@language' => ( isset ( $ activectx [ '@language' ] ) ) ? $ activectx [ '@language' ] : null , '@index' => null , '@container' => null , 'isKeyword' => false , 'compactArrays' => true ) ; if ( in_array ( $ property , self :: $ keywords ) ) { $ result [ '@type' ] = ( ( '@id' === $ property ) || ( '@type' === $ property ) ) ? '@id' : null ; $ result [ '@language' ] = null ; $ result [ 'isKeyword' ] = true ; $ result [ 'compactArrays' ] = ( bool ) ( ( '@list' !== $ property ) && ( '@graph' !== $ property ) ) ; } else { $ def = ( isset ( $ activectx [ $ property ] ) ) ? $ activectx [ $ property ] : null ; if ( null !== $ def ) { $ result [ '@id' ] = $ def [ '@id' ] ; $ result [ '@reverse' ] = $ def [ '@reverse' ] ; if ( isset ( $ def [ '@type' ] ) ) { $ result [ '@type' ] = $ def [ '@type' ] ; $ result [ '@language' ] = null ; } elseif ( array_key_exists ( '@language' , $ def ) ) { $ result [ '@language' ] = $ def [ '@language' ] ; } if ( isset ( $ def [ '@container' ] ) ) { $ result [ '@container' ] = $ def [ '@container' ] ; if ( ( '@list' === $ def [ '@container' ] ) || ( '@set' === $ def [ '@container' ] ) ) { $ result [ 'compactArrays' ] = false ; } } } } if ( $ only ) { return ( isset ( $ result [ $ only ] ) ) ? $ result [ $ only ] : null ; } return $ result ; }
|
Returns a property s definition
|
51,306
|
private function loadDocument ( $ input ) { if ( false === is_string ( $ input ) ) { return $ input ; } $ document = $ this -> documentLoader -> loadDocument ( $ input ) ; return $ document -> document ; }
|
Load a JSON - LD document
|
51,307
|
public function createInverseContext ( $ activectx ) { $ inverseContext = array ( ) ; $ defaultLanguage = isset ( $ activectx [ '@language' ] ) ? $ activectx [ '@language' ] : '@null' ; $ propertyGenerators = isset ( $ activectx [ '@propertyGenerators' ] ) ? $ activectx [ '@propertyGenerators' ] : array ( ) ; unset ( $ activectx [ '@base' ] ) ; unset ( $ activectx [ '@vocab' ] ) ; unset ( $ activectx [ '@language' ] ) ; unset ( $ activectx [ '@propertyGenerators' ] ) ; $ activectx = array_merge ( $ activectx , $ propertyGenerators ) ; unset ( $ propertyGenerators ) ; uksort ( $ activectx , array ( $ this , 'sortTerms' ) ) ; foreach ( $ activectx as $ term => $ def ) { if ( null === $ def [ '@id' ] ) { continue ; } $ container = ( isset ( $ def [ '@container' ] ) ) ? $ def [ '@container' ] : '@null' ; $ iri = $ def [ '@id' ] ; if ( false === isset ( $ inverseContext [ $ iri ] [ 'term' ] ) && ( false === $ def [ '@reverse' ] ) ) { $ inverseContext [ $ iri ] [ 'term' ] = $ term ; } $ typeOrLang = '@null' ; $ typeLangValue = '@null' ; if ( true === $ def [ '@reverse' ] ) { $ typeOrLang = '@type' ; $ typeLangValue = '@reverse' ; } elseif ( isset ( $ def [ '@type' ] ) ) { $ typeOrLang = '@type' ; $ typeLangValue = $ def [ '@type' ] ; } elseif ( array_key_exists ( '@language' , $ def ) ) { $ typeOrLang = '@language' ; $ typeLangValue = ( null === $ def [ '@language' ] ) ? '@null' : $ def [ '@language' ] ; } else { if ( false === isset ( $ inverseContext [ $ iri ] [ $ container ] [ '@language' ] [ $ defaultLanguage ] ) ) { $ inverseContext [ $ iri ] [ $ container ] [ '@language' ] [ $ defaultLanguage ] = $ term ; } } if ( false === isset ( $ inverseContext [ $ iri ] [ $ container ] [ $ typeOrLang ] [ $ typeLangValue ] ) ) { $ inverseContext [ $ iri ] [ $ container ] [ $ typeOrLang ] [ $ typeLangValue ] = $ term ; } } uksort ( $ inverseContext , array ( $ this , 'sortTerms' ) ) ; $ inverseContext = array_reverse ( $ inverseContext ) ; return $ inverseContext ; }
|
Creates an inverse context to simplify IRI compaction
|
51,308
|
private function getBlankNodeId ( $ id = null ) { if ( ( null !== $ id ) && isset ( $ this -> blankNodeMap [ $ id ] ) ) { return $ this -> blankNodeMap [ $ id ] ; } $ bnode = '_:b' . $ this -> blankNodeCounter ++ ; $ this -> blankNodeMap [ $ id ] = $ bnode ; return $ bnode ; }
|
Generate a new blank node identifier
|
51,309
|
public function flatten ( $ element ) { $ nodeMap = new JsonObject ( ) ; $ nodeMap -> { '-' . JsonLD :: DEFAULT_GRAPH } = new JsonObject ( ) ; $ this -> generateNodeMap ( $ nodeMap , $ element ) ; $ defaultGraph = $ nodeMap -> { '-' . JsonLD :: DEFAULT_GRAPH } ; unset ( $ nodeMap -> { '-' . JsonLD :: DEFAULT_GRAPH } ) ; foreach ( $ nodeMap as $ graphName => $ graph ) { if ( ! isset ( $ defaultGraph -> { $ graphName } ) ) { $ defaultGraph -> { $ graphName } = new JsonObject ( ) ; $ defaultGraph -> { $ graphName } -> { '@id' } = substr ( $ graphName , 1 ) ; } $ graph = ( array ) $ graph ; ksort ( $ graph ) ; $ defaultGraph -> { $ graphName } -> { '@graph' } = array_values ( array_filter ( $ graph , array ( $ this , 'hasNodeProperties' ) ) ) ; } $ defaultGraph = ( array ) $ defaultGraph ; ksort ( $ defaultGraph ) ; return array_values ( array_filter ( $ defaultGraph , array ( $ this , 'hasNodeProperties' ) ) ) ; }
|
Flattens a JSON - LD document
|
51,310
|
public function toRdf ( array $ document ) { $ nodeMap = new JsonObject ( ) ; $ nodeMap -> { '-' . JsonLD :: DEFAULT_GRAPH } = new JsonObject ( ) ; $ this -> generateNodeMap ( $ nodeMap , $ document ) ; $ result = array ( ) ; foreach ( $ nodeMap as $ graphName => $ graph ) { $ graphName = substr ( $ graphName , 1 ) ; if ( JsonLD :: DEFAULT_GRAPH === $ graphName ) { $ activegraph = null ; } else { $ activegraph = new IRI ( $ graphName ) ; if ( false === $ activegraph -> isAbsolute ( ) ) { continue ; } } foreach ( $ graph as $ subject => $ node ) { $ activesubj = new IRI ( substr ( $ subject , 1 ) ) ; if ( false === $ activesubj -> isAbsolute ( ) ) { continue ; } foreach ( $ node as $ property => $ values ) { if ( '@id' === $ property ) { continue ; } elseif ( '@type' === $ property ) { $ activeprty = new IRI ( RdfConstants :: RDF_TYPE ) ; foreach ( $ values as $ value ) { $ result [ ] = new Quad ( $ activesubj , $ activeprty , new IRI ( $ value ) , $ activegraph ) ; } continue ; } elseif ( '@' === $ property [ 0 ] ) { continue ; } if ( ( 0 === strncmp ( $ property , '_:' , 2 ) ) && ( false === $ this -> generalizedRdf ) ) { continue ; } $ activeprty = new IRI ( $ property ) ; if ( false === $ activeprty -> isAbsolute ( ) ) { continue ; } foreach ( $ values as $ value ) { if ( property_exists ( $ value , '@list' ) ) { $ quads = array ( ) ; $ head = $ this -> listToRdf ( $ value -> { '@list' } , $ quads , $ activegraph ) ; $ result [ ] = new Quad ( $ activesubj , $ activeprty , $ head , $ activegraph ) ; foreach ( $ quads as $ quad ) { $ result [ ] = $ quad ; } } else { $ object = $ this -> elementToRdf ( $ value ) ; if ( null === $ object ) { continue ; } $ result [ ] = new Quad ( $ activesubj , $ activeprty , $ object , $ activegraph ) ; } } } } } return $ result ; }
|
Converts an expanded JSON - LD document to RDF quads
|
51,311
|
private function elementToRdf ( JsonObject $ element ) { if ( property_exists ( $ element , '@value' ) ) { return Value :: fromJsonLd ( $ element ) ; } $ iri = new IRI ( $ element -> { '@id' } ) ; return $ iri -> isAbsolute ( ) ? $ iri : null ; }
|
Converts a JSON - LD element to a RDF Quad object
|
51,312
|
public function frame ( $ element , $ frame ) { if ( ( false === is_array ( $ frame ) ) || ( 1 !== count ( $ frame ) ) || ( false === is_object ( $ frame [ 0 ] ) ) ) { throw new JsonLdException ( JsonLdException :: UNSPECIFIED , 'The frame is invalid. It must be a single object.' , $ frame ) ; } $ frame = $ frame [ 0 ] ; $ options = new JsonObject ( ) ; $ options -> { '@embed' } = true ; $ options -> { '@embedChildren' } = true ; foreach ( self :: $ framingKeywords as $ keyword ) { if ( property_exists ( $ frame , $ keyword ) ) { $ options -> { $ keyword } = $ frame -> { $ keyword } ; unset ( $ frame -> { $ keyword } ) ; } elseif ( false === property_exists ( $ options , $ keyword ) ) { $ options -> { $ keyword } = false ; } } $ procOptions = new JsonObject ( ) ; $ procOptions -> base = ( string ) $ this -> baseIri ; $ procOptions -> compactArrays = $ this -> compactArrays ; $ procOptions -> optimize = $ this -> optimize ; $ procOptions -> useNativeTypes = $ this -> useNativeTypes ; $ procOptions -> useRdfType = $ this -> useRdfType ; $ procOptions -> produceGeneralizedRdf = $ this -> generalizedRdf ; $ procOptions -> documentFactory = $ this -> documentFactory ; $ procOptions -> documentLoader = $ this -> documentLoader ; $ processor = new Processor ( $ procOptions ) ; $ graph = JsonLD :: MERGED_GRAPH ; if ( property_exists ( $ frame , '@graph' ) ) { $ graph = JsonLD :: DEFAULT_GRAPH ; } $ nodeMap = new JsonObject ( ) ; $ nodeMap -> { '-' . $ graph } = new JsonObject ( ) ; $ processor -> generateNodeMap ( $ nodeMap , $ element , $ graph ) ; $ nodeMap = ( array ) $ nodeMap ; foreach ( $ nodeMap as & $ nodes ) { $ nodes = ( array ) $ nodes ; ksort ( $ nodes ) ; $ nodes = ( object ) $ nodes ; } $ nodeMap = ( object ) $ nodeMap ; unset ( $ processor ) ; $ result = array ( ) ; foreach ( $ nodeMap -> { '-' . $ graph } as $ node ) { $ this -> nodeMatchesFrame ( $ node , $ frame , $ options , $ nodeMap , $ graph , $ result ) ; } return $ result ; }
|
Frames a JSON - LD document according a supplied frame
|
51,313
|
private function addMissingNodeProperties ( $ node , $ options , $ nodeMap , $ graph , & $ result , $ path ) { foreach ( $ node as $ property => $ value ) { if ( property_exists ( $ result , $ property ) ) { continue ; } if ( true === $ options -> { '@embedChildren' } ) { if ( false === is_array ( $ value ) ) { $ result -> { $ property } = unserialize ( serialize ( $ value ) ) ; continue ; } $ result -> { $ property } = array ( ) ; foreach ( $ value as $ item ) { if ( is_object ( $ item ) ) { if ( property_exists ( $ item , '@id' ) ) { $ item = $ nodeMap -> { '-' . $ graph } -> { '-' . $ item -> { '@id' } } ; } $ this -> nodeMatchesFrame ( $ item , null , $ options , $ nodeMap , $ graph , $ result -> { $ property } , $ path ) ; } else { $ result -> { $ property } [ ] = $ item ; } } } else { $ result -> { $ property } = unserialize ( serialize ( $ value ) ) ; } } }
|
Adds all properties from node to result if they haven t been added yet
|
51,314
|
private static function setProperty ( & $ object , $ property , $ value , $ errorCode = null ) { if ( property_exists ( $ object , $ property ) && ( false === self :: subtreeEquals ( $ object -> { $ property } , $ value ) ) ) { if ( $ errorCode ) { throw new JsonLdException ( $ errorCode , "Object already contains a property \"$property\"." , $ object ) ; } throw new JsonLdException ( JsonLdException :: UNSPECIFIED , "Object already contains a property \"$property\"." , $ object ) ; } $ object -> { $ property } = $ value ; }
|
Adds a property to an object if it doesn t exist yet
|
51,315
|
private static function mergeIntoProperty ( & $ object , $ property , $ value , $ alwaysArray = false , $ unique = false ) { if ( null === $ value ) { return ; } if ( is_array ( $ value ) ) { if ( ( 0 === count ( $ value ) ) && ( false === property_exists ( $ object , $ property ) ) ) { $ object -> { $ property } = array ( ) ; } foreach ( $ value as $ val ) { static :: mergeIntoProperty ( $ object , $ property , $ val , $ alwaysArray , $ unique ) ; } return ; } if ( property_exists ( $ object , $ property ) ) { if ( false === is_array ( $ object -> { $ property } ) ) { $ object -> { $ property } = array ( $ object -> { $ property } ) ; } if ( $ unique ) { foreach ( $ object -> { $ property } as $ item ) { if ( self :: subtreeEquals ( $ item , $ value ) ) { return ; } } } $ object -> { $ property } [ ] = $ value ; } else { $ object -> { $ property } = ( $ alwaysArray ) ? array ( $ value ) : $ value ; } }
|
Merges a value into a property of an object
|
51,316
|
private static function sortTerms ( $ a , $ b ) { $ lenA = strlen ( $ a ) ; $ lenB = strlen ( $ b ) ; if ( $ lenA < $ lenB ) { return - 1 ; } elseif ( $ lenA === $ lenB ) { return strcmp ( $ a , $ b ) ; } else { return 1 ; } }
|
Compares two values by their length and then lexicographically
|
51,317
|
private static function objectToJsonLd ( $ object , $ useNativeTypes = true ) { if ( $ object instanceof IRI ) { $ result = new JsonObject ( ) ; $ result -> { '@id' } = ( string ) $ object ; return $ result ; } elseif ( $ object instanceof Value ) { return $ object -> toJsonLd ( $ useNativeTypes ) ; } return $ object ; }
|
Converts an object to a JSON - LD representation
|
51,318
|
protected function resolveIri ( $ iri ) { if ( null === $ this -> document ) { $ base = new IRI ( ) ; } else { $ base = $ this -> document -> getIri ( true ) ; } return $ base -> resolve ( $ iri ) ; }
|
Resolves an IRI against the document s IRI
|
51,319
|
public static function getYoutubeEmbedUrl ( $ videoUrl ) { $ embedLink = '' ; $ embedINI = eZINI :: instance ( 'embedtag.ini' ) ; preg_match ( self :: YOUTUBE_VIDEOID_REGEXP , $ videoUrl , $ matches ) ; if ( isset ( $ matches [ 'videoId' ] ) ) { $ embedLink = str_replace ( '$$$VIDEO$$$' , $ matches [ 'videoId' ] , $ embedINI -> variable ( 'YoutubeSettings' , 'EmbedLinkPattern' ) ) ; } return array ( 'result' => $ embedLink ) ; }
|
Returns embed URL for a Youtube video from its link
|
51,320
|
public static function getDailymotionEmbedUrl ( $ videoUrl ) { $ embedLink = '' ; $ embedINI = eZINI :: instance ( 'embedtag.ini' ) ; preg_match ( self :: DAILYMOTION_VIDEOID_REGEXP , $ videoUrl , $ matches ) ; if ( isset ( $ matches [ 'videoId' ] ) ) { $ embedLink = str_replace ( '$$$VIDEO$$$' , $ matches [ 'videoId' ] , $ embedINI -> variable ( 'DailymotionSettings' , 'EmbedLinkPattern' ) ) ; } return array ( 'result' => $ embedLink ) ; }
|
Returns embed URL for a DailyMotion video from its link
|
51,321
|
public static function getVimeoEmbedUrl ( $ videoUrl ) { $ embedLink = '' ; $ embedINI = eZINI :: instance ( 'embedtag.ini' ) ; preg_match ( self :: VIMEO_VIDEOID_REGEXP , $ videoUrl , $ matches ) ; if ( isset ( $ matches [ 'videoId' ] ) ) { $ embedLink = str_replace ( '$$$VIDEO$$$' , $ matches [ 'videoId' ] , $ embedINI -> variable ( 'VimeoSettings' , 'EmbedLinkPattern' ) ) ; } return array ( 'result' => $ embedLink ) ; }
|
Returns embed URL for a Vimeo video from its link
|
51,322
|
public static function cacheModule ( \ core_kernel_classes_Resource $ module ) { $ controllerClassName = MapHelper :: getControllerFromUri ( $ module -> getUri ( ) ) ; self :: flushControllerAccess ( $ controllerClassName ) ; self :: getControllerAccess ( $ controllerClassName ) ; }
|
force recache of a controller
|
51,323
|
public static function getControllerAccess ( $ controllerClassName ) { try { $ returnValue = self :: getCacheImplementation ( ) -> get ( self :: SERIAL_PREFIX_MODULE . $ controllerClassName ) ; } catch ( \ common_cache_Exception $ e ) { $ extId = MapHelper :: getExtensionFromController ( $ controllerClassName ) ; $ extension = MapHelper :: getUriForExtension ( $ extId ) ; $ module = MapHelper :: getUriForController ( $ controllerClassName ) ; $ roleClass = new \ core_kernel_classes_Class ( GenerisRdf :: CLASS_ROLE ) ; $ accessProperty = new \ core_kernel_classes_Property ( AccessService :: PROPERTY_ACL_GRANTACCESS ) ; $ returnValue = array ( 'module' => array ( ) , 'actions' => array ( ) ) ; $ roles = $ roleClass -> searchInstances ( array ( $ accessProperty -> getUri ( ) => $ extension ) , array ( 'recursive' => true , 'like' => false ) ) ; foreach ( $ roles as $ grantedRole ) { $ returnValue [ 'module' ] [ ] = $ grantedRole -> getUri ( ) ; } $ filters = array ( $ accessProperty -> getUri ( ) => $ module ) ; $ options = array ( 'recursive' => true , 'like' => false ) ; foreach ( $ roleClass -> searchInstances ( $ filters , $ options ) as $ grantedRole ) { $ returnValue [ 'module' ] [ ] = $ grantedRole -> getUri ( ) ; } foreach ( ControllerHelper :: getActions ( $ controllerClassName ) as $ actionName ) { $ actionUri = MapHelper :: getUriForAction ( $ controllerClassName , $ actionName ) ; $ rolesForAction = $ roleClass -> searchInstances ( array ( $ accessProperty -> getUri ( ) => $ actionUri ) , array ( 'recursive' => true , 'like' => false ) ) ; if ( ! empty ( $ rolesForAction ) ) { $ actionName = MapHelper :: getActionFromUri ( $ actionUri ) ; $ returnValue [ 'actions' ] [ $ actionName ] = array ( ) ; foreach ( $ rolesForAction as $ roleResource ) { $ returnValue [ 'actions' ] [ $ actionName ] [ ] = $ roleResource -> getUri ( ) ; } } } self :: getCacheImplementation ( ) -> put ( $ returnValue , self :: SERIAL_PREFIX_MODULE . $ controllerClassName ) ; } return $ returnValue ; }
|
Return the cached description of the roles that have access to this controller
|
51,324
|
private static function buildModuleSerial ( \ core_kernel_classes_Resource $ module ) { $ returnValue = ( string ) '' ; $ uri = explode ( '#' , $ module -> getUri ( ) ) ; list ( $ type , $ extId ) = explode ( '_' , $ uri [ 1 ] ) ; $ returnValue = self :: SERIAL_PREFIX_MODULE . $ extId . urlencode ( $ module -> getUri ( ) ) ; return ( string ) $ returnValue ; }
|
Short description of method buildModuleSerial
|
51,325
|
public function makeEMAUri ( $ ext , $ mod = null , $ act = null ) { $ returnValue = ( string ) '' ; $ returnValue = self :: FUNCACL_NS . '#' ; if ( ! is_null ( $ act ) ) { $ type = 'a' ; } else { if ( ! is_null ( $ mod ) ) { $ type = 'm' ; } else { $ type = 'e' ; } } $ returnValue .= $ type . '_' . $ ext ; if ( ! is_null ( $ mod ) ) { $ returnValue .= '_' . $ mod ; } if ( ! is_null ( $ act ) ) { $ returnValue .= '_' . $ act ; } return ( string ) $ returnValue ; }
|
Short description of method makeEMAUri
|
51,326
|
public function hasAccess ( $ action , $ controller , $ extension , $ parameters = array ( ) ) { $ user = \ common_session_SessionManager :: getSession ( ) -> getUser ( ) ; $ uri = ModuleAccessService :: singleton ( ) -> makeEMAUri ( $ extension , $ controller ) ; $ controllerClassName = MapHelper :: getControllerFromUri ( $ uri ) ; return self :: accessPossible ( $ user , $ controllerClassName , $ action ) ; }
|
Compatibility class for old implementation
|
51,327
|
public static function getModules ( $ extensionId ) { $ returnValue = array ( ) ; foreach ( ControllerHelper :: getControllers ( $ extensionId ) as $ controllerClassName ) { $ shortName = strpos ( $ controllerClassName , '\\' ) !== false ? substr ( $ controllerClassName , strrpos ( $ controllerClassName , '\\' ) + 1 ) : substr ( $ controllerClassName , strrpos ( $ controllerClassName , '_' ) + 1 ) ; $ uri = AccessService :: singleton ( ) -> makeEMAUri ( $ extensionId , $ shortName ) ; $ returnValue [ $ uri ] = new \ core_kernel_classes_Resource ( $ uri ) ; } return ( array ) $ returnValue ; }
|
returns the modules of an extension from the ontology
|
51,328
|
public static function getActions ( \ core_kernel_classes_Resource $ module ) { $ returnValue = array ( ) ; $ controllerClassName = MapHelper :: getControllerFromUri ( $ module -> getUri ( ) ) ; try { foreach ( ControllerHelper :: getActions ( $ controllerClassName ) as $ actionName ) { $ uri = MapHelper :: getUriForAction ( $ controllerClassName , $ actionName ) ; $ returnValue [ $ uri ] = new \ core_kernel_classes_Resource ( $ uri ) ; } } catch ( \ ReflectionException $ e ) { } return ( array ) $ returnValue ; }
|
returns the actions of a module from the ontology
|
51,329
|
public function index ( ) { $ this -> defaultData ( ) ; $ rolesc = new \ core_kernel_classes_Class ( GenerisRdf :: CLASS_ROLE ) ; $ roles = array ( ) ; foreach ( $ rolesc -> getInstances ( true ) as $ id => $ r ) { $ roles [ ] = array ( 'id' => $ id , 'label' => $ r -> getLabel ( ) ) ; } usort ( $ roles , function ( $ a , $ b ) { return strcmp ( $ a [ 'label' ] , $ b [ 'label' ] ) ; } ) ; $ this -> setData ( 'roles' , $ roles ) ; $ this -> setView ( 'list.tpl' ) ; }
|
Show the list of roles
|
51,330
|
public function getActions ( ) { $ this -> beforeAction ( ) ; $ role = new \ core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'role' ) ) ; $ included = array ( ) ; foreach ( \ tao_models_classes_RoleService :: singleton ( ) -> getIncludedRoles ( $ role ) as $ includedRole ) { $ included [ ] = $ includedRole -> getUri ( ) ; } $ module = new \ core_kernel_classes_Resource ( $ this -> getRequestParameter ( 'module' ) ) ; $ controllerClassName = MapHelper :: getControllerFromUri ( $ module -> getUri ( ) ) ; $ controllerAccess = CacheHelper :: getControllerAccess ( $ controllerClassName ) ; $ actions = array ( ) ; foreach ( ControllerHelper :: getActions ( $ controllerClassName ) as $ actionName ) { $ uri = MapHelper :: getUriForAction ( $ controllerClassName , $ actionName ) ; $ part = explode ( '#' , $ uri ) ; list ( $ type , $ extId , $ modId , $ actId ) = explode ( '_' , $ part [ 1 ] ) ; $ allowedRoles = isset ( $ controllerAccess [ 'actions' ] [ $ actionName ] ) ? array_merge ( $ controllerAccess [ 'module' ] , $ controllerAccess [ 'actions' ] [ $ actionName ] ) : $ controllerAccess [ 'module' ] ; $ access = count ( array_intersect ( $ included , $ allowedRoles ) ) > 0 ? self :: ACCESS_INHERITED : ( in_array ( $ role -> getUri ( ) , $ allowedRoles ) ? self :: ACCESS_FULL : self :: ACCESS_NONE ) ; $ actions [ $ actId ] = array ( 'uri' => $ uri , 'access' => $ access , 'locked' => $ this -> isLocked ( ) , ) ; } ksort ( $ actions ) ; $ this -> returnJson ( $ actions ) ; }
|
Shows the access to the actions of a controller for a specific role
|
51,331
|
public function setIdentifier ( $ value = 'REQUIRED' ) { if ( $ this -> isEmpty ( $ value ) ) { throw new TpvException ( 'Please add value' ) ; } $ this -> _setParameters [ 'DS_MERCHANT_IDENTIFIER' ] = $ value ; return $ this ; }
|
Set identifier required
|
51,332
|
public function getOrderNotification ( $ parameters ) { $ order = '' ; foreach ( $ parameters as $ key => $ value ) { if ( strtolower ( $ key ) === 'ds_order' ) { $ order = $ value ; } } return $ order ; }
|
Get Ds_Order of Notification
|
51,333
|
public function setTransactiontype ( $ transaction = 0 ) { if ( $ this -> isEmpty ( $ transaction ) ) { throw new TpvException ( 'Please add transaction type' ) ; } $ this -> _setParameters [ 'DS_MERCHANT_TRANSACTIONTYPE' ] = $ transaction ; return $ this ; }
|
Set Transaction type
|
51,334
|
public function generateMerchantSignature ( $ key ) { $ key = $ this -> decodeBase64 ( $ key ) ; $ merchant_parameter = $ this -> generateMerchantParameters ( ) ; $ key = $ this -> encrypt_3DES ( $ this -> getOrder ( ) , $ key ) ; $ result = $ this -> hmac256 ( $ merchant_parameter , $ key ) ; return $ this -> encodeBase64 ( $ result ) ; }
|
Generate Merchant Signature
|
51,335
|
public function generateMerchantSignatureNotification ( $ key , $ data ) { $ key = $ this -> decodeBase64 ( $ key ) ; $ decode = $ this -> base64_url_decode ( $ data ) ; $ parameters = $ this -> JsonToArray ( $ decode ) ; $ order = $ this -> getOrderNotification ( $ parameters ) ; $ key = $ this -> encrypt_3DES ( $ order , $ key ) ; $ result = $ this -> hmac256 ( $ data , $ key ) ; return $ this -> base64_url_encode ( $ result ) ; }
|
Generate Merchant Signature Notification
|
51,336
|
public function setLanguage ( $ languageCode = '001' ) { if ( $ this -> isEmpty ( $ languageCode ) ) { throw new TpvException ( 'Add language code' ) ; } $ this -> _setParameters [ 'DS_MERCHANT_CONSUMERLANGUAGE' ] = trim ( $ languageCode ) ; return $ this ; }
|
Set language code by default 001 = Spanish
|
51,337
|
public function setMerchantData ( $ merchantdata = '' ) { if ( $ this -> isEmpty ( $ merchantdata ) ) { throw new TpvException ( 'Add merchant data' ) ; } $ this -> _setParameters [ 'DS_MERCHANT_MERCHANTDATA' ] = trim ( $ merchantdata ) ; return $ this ; }
|
Optional field for the trade to be included in the data sent by the on - line response to trade if this option has been chosen .
|
51,338
|
public function setAttributesSubmit ( $ name = 'btn_submit' , $ id = 'btn_submit' , $ value = 'Send' , $ style = '' , $ cssClass = '' ) { $ this -> _setNameSubmit = $ name ; $ this -> _setIdSubmit = $ id ; $ this -> _setValueSubmit = $ value ; $ this -> _setStyleSubmit = $ style ; $ this -> _setClassSubmit = $ cssClass ; return $ this ; }
|
Set Attributes to submit
|
51,339
|
public function executeRedirection ( $ return = false ) { $ html = $ this -> createForm ( ) ; $ html .= '<script>document.forms["' . $ this -> _setNameForm . '"].submit();</script>' ; if ( ! $ return ) { echo $ html ; return null ; } return $ html ; }
|
Execute redirection to TPV
|
51,340
|
public function createForm ( ) { $ form = ' <form action="' . $ this -> _setEnvironment . '" method="post" id="' . $ this -> _setIdForm . '" name="' . $ this -> _setNameForm . '" > <input type="hidden" name="Ds_MerchantParameters" value="' . $ this -> generateMerchantParameters ( ) . '"/> <input type="hidden" name="Ds_Signature" value="' . $ this -> _setSignature . '"/> <input type="hidden" name="Ds_SignatureVersion" value="' . $ this -> _setVersion . '"/> <input type="submit" name="' . $ this -> _setNameSubmit . '" id="' . $ this -> _setIdSubmit . '" value="' . $ this -> _setValueSubmit . '" ' . ( $ this -> _setStyleSubmit != '' ? ' style="' . $ this -> _setStyleSubmit . '"' : '' ) . ' ' . ( $ this -> _setClassSubmit != '' ? ' class="' . $ this -> _setClassSubmit . '"' : '' ) . '> </form> ' ; return $ form ; }
|
Generate form html
|
51,341
|
protected function encrypt_3DES ( $ data , $ key ) { $ iv = "\0\0\0\0\0\0\0\0" ; $ data_padded = $ data ; if ( strlen ( $ data_padded ) % 8 ) { $ data_padded = str_pad ( $ data_padded , strlen ( $ data_padded ) + 8 - strlen ( $ data_padded ) % 8 , "\0" ) ; } return openssl_encrypt ( $ data_padded , "DES-EDE3-CBC" , $ key , OPENSSL_RAW_DATA | OPENSSL_NO_PADDING , $ iv ) ; }
|
Encrypt to 3DES
|
51,342
|
protected function isValidOrder ( $ order = '' ) { return ( strlen ( $ order ) >= 4 && strlen ( $ order ) <= 12 && is_numeric ( substr ( $ order , 0 , 4 ) ) ) ? true : false ; }
|
Check is order is valid
|
51,343
|
public function writeError ( $ line , $ check , $ message , $ level = WARNING ) { foreach ( $ this -> reporters as $ reporter ) { $ reporter -> writeError ( $ line , $ check , $ message , $ level ) ; } }
|
For every error this function is called once with the line where the error occurred and the actual error message It is the responsibility of the derived class to appropriately format it and write it into the output file
|
51,344
|
protected function writeFragment ( $ fragment ) { $ fileHandle = fopen ( $ this -> outputFile , $ this -> writeMode ) ; fwrite ( $ fileHandle , $ fragment ) ; fclose ( $ fileHandle ) ; $ this -> writeMode = 'a' ; }
|
Writes an HTML fragment to the output file .
|
51,345
|
private function _readTemplate ( $ templateFile ) { $ filename = PHPCHECKSTYLE_HOME_DIR . "/html/template/" . $ templateFile . ".tmpl" ; $ handle = fopen ( $ filename , "r" ) ; $ contents = fread ( $ handle , filesize ( $ filename ) ) ; fclose ( $ handle ) ; return $ contents ; }
|
Read the content of a template file .
|
51,346
|
private function _fillTemplate ( $ template , $ values ) { foreach ( $ values as $ key => $ value ) { $ template = str_replace ( $ key , $ value , $ template ) ; } return $ template ; }
|
Replace some values in a template file .
|
51,347
|
private function _createDOMLine ( $ a1 , $ b1 , $ c1 , $ d1 , $ e1 , $ f1 ) { $ line = $ this -> document -> createElement ( "tr" ) ; $ cola = $ this -> document -> createElement ( "td" , $ a1 ) ; $ colb = $ this -> document -> createElement ( "td" , $ b1 ) ; $ colc = $ this -> document -> createElement ( "td" , $ c1 ) ; $ cold = $ this -> document -> createElement ( "td" , $ d1 ) ; $ cole = $ this -> document -> createElement ( "td" , $ e1 ) ; $ colf = $ this -> document -> createElement ( "td" , $ f1 ) ; $ line -> appendChild ( $ cola ) ; $ line -> appendChild ( $ colb ) ; $ line -> appendChild ( $ colc ) ; $ line -> appendChild ( $ cold ) ; $ line -> appendChild ( $ cole ) ; $ line -> appendChild ( $ colf ) ; return $ line ; }
|
Create the DOM for a line of a table
|
51,348
|
public function getConfigItems ( $ config ) { $ config = strtolower ( $ config ) ; return isset ( $ this -> config [ $ config ] ) ? $ this -> config [ $ config ] : array ( ) ; }
|
Return a list of items associed with a configuration .
|
51,349
|
public function isException ( $ test , $ value ) { $ exceptions = $ this -> getTestExceptions ( $ test ) ; return ( ! empty ( $ exceptions ) && in_array ( $ value , $ exceptions ) ) ; }
|
Indicate if a value is an exception for the test .
|
51,350
|
public function parse ( ) { $ fp = fopen ( $ this -> file , "r" ) ; if ( ! $ fp ) { throw new Exception ( "Could not open XML input file" ) ; } $ data = fread ( $ fp , 4096 ) ; while ( $ data ) { if ( ! xml_parse ( $ this -> xmlParser , $ data , feof ( $ fp ) ) ) { $ errorString = xml_error_string ( xml_get_error_code ( $ this -> xmlParser ) ) ; $ errorLineNo = xml_get_current_line_number ( $ this -> xmlParser ) ; $ msg = sprintf ( "Warning: XML error: %s at line %d" , $ errorString , $ errorLineNo ) ; echo $ msg ; $ this -> config = array ( ) ; } $ data = fread ( $ fp , 4096 ) ; } }
|
Parses the configuration file and stores the values .
|
51,351
|
function getStackDump ( ) { $ dump = "" ; $ stackTypes = array ( "FUNCTION" , "INTERFACE" , "CLASS" ) ; foreach ( $ this -> statements as $ item ) { $ dump .= $ item -> type ; if ( in_array ( $ item -> type , $ stackTypes ) ) { $ dump .= "(" . $ item -> name . ")" ; } $ dump .= " -> " ; } return $ dump ; }
|
Display the current branching stack .
|
51,352
|
function getCurrentStackItem ( ) { $ topItem = end ( $ this -> statements ) ; if ( ! empty ( $ topItem ) ) { return $ topItem ; } else { return $ this -> getDefaultItem ( ) ; } }
|
Return the top stack item .
|
51,353
|
function getParentFunction ( ) { for ( $ i = $ this -> count ( ) - 1 ; $ i >= 0 ; $ i -- ) { $ item = $ this -> statements [ $ i ] ; if ( $ item -> type === "FUNCTION" ) { return $ item ; } } return $ this -> getDefaultItem ( ) ; }
|
Return the parent function .
|
51,354
|
function getParentClass ( ) { for ( $ i = $ this -> count ( ) - 1 ; $ i >= 0 ; $ i -- ) { $ item = $ this -> statements [ $ i ] ; if ( $ item -> type === "CLASS" || $ item -> type === "INTERFACE" ) { return $ item ; } } return $ this -> getDefaultItem ( ) ; }
|
Return the parent class .
|
51,355
|
public function dumpTokens ( ) { $ result = "" ; foreach ( $ this -> tokens as $ token ) { $ result .= $ token -> toString ( ) . PHP_EOL ; } return $ result ; }
|
Dump the tokens of the file .
|
51,356
|
public function peekTokenAt ( $ position ) { if ( $ position < count ( $ this -> tokens ) ) { return $ this -> tokens [ $ position ] ; } else { return null ; } }
|
Get the token at a given position .
|
51,357
|
public function peekNextToken ( ) { if ( $ this -> index < ( count ( $ this -> tokens ) - 1 ) ) { return $ this -> tokens [ $ this -> index + 1 ] ; } else { return null ; } }
|
Returns the next token without moving the index .
|
51,358
|
public function peekNextValidToken ( $ startPos = null , $ stopOnNewLine = false ) { $ pos = $ this -> getCurrentPosition ( ) + 1 ; if ( $ startPos !== null ) { $ pos = $ startPos ; } $ token = null ; $ nbTokens = count ( $ this -> tokens ) ; while ( $ pos < $ nbTokens ) { $ token = $ this -> tokens [ $ pos ] ; $ pos ++ ; if ( isset ( $ this -> ignoreTokens [ $ token -> id ] ) ) { continue ; } else if ( $ token -> id === T_NEW_LINE ) { if ( $ stopOnNewLine ) { break ; } else { continue ; } } else { break ; } } return $ token ; }
|
Peeks at the next valid token . A valid token is one that is neither a whitespace or a comment
|
51,359
|
public function peekPrvsValidToken ( $ startPos = null ) { if ( $ startPos === null ) { $ pos = $ this -> getCurrentPosition ( ) - 1 ; } else { $ pos = $ startPos ; } $ token = null ; while ( $ pos > 0 ) { $ token = $ this -> tokens [ $ pos ] ; $ pos -- ; if ( isset ( $ this -> ignoreTokens [ $ token -> id ] ) ) { continue ; } else if ( $ token -> id === T_NEW_LINE ) { continue ; } else { break ; } } return $ token ; }
|
Peeks at the previous valid token . A valid token is one that is neither a whitespace or a comment
|
51,360
|
public function reset ( ) { $ this -> index = 0 ; $ this -> tokens = array ( ) ; $ this -> newTokens = array ( ) ; $ this -> tokenNumber = 0 ; $ this -> lineNumber = 1 ; }
|
Resets all local variables
|
51,361
|
public function checkToken ( $ token , $ id , $ text = false ) { $ result = false ; if ( $ token -> id === $ id ) { if ( $ text ) { $ result = $ token -> text === $ text ; } else { $ result = true ; } } return $ result ; }
|
Check if a token is equal to a given token ID
|
51,362
|
private function _identifyTokens ( $ tokenText , $ tokenID ) { $ splitData = preg_split ( '#(\r\n|\n|\r)#' , $ tokenText , null , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ) ; foreach ( $ splitData as $ data ) { $ tokenInfo = new TokenInfo ( ) ; $ tokenInfo -> text = $ data ; $ tokenInfo -> position = $ this -> tokenNumber ; $ tokenInfo -> line = $ this -> lineNumber ; if ( $ data === "\r\n" || $ data === "\n" || $ data === "\r" ) { $ tokenInfo -> id = T_NEW_LINE ; $ this -> lineNumber ++ ; } else if ( $ data === "\t" ) { $ tokenInfo -> id = T_TAB ; } else { $ tokenInfo -> id = $ tokenID ; } $ this -> tokenNumber ++ ; if ( $ tokenInfo -> id === T_UNKNOWN ) { switch ( $ tokenInfo -> text ) { case ";" : $ tokenInfo -> id = T_SEMICOLON ; break ; case "{" : $ tokenInfo -> id = T_BRACES_OPEN ; break ; case "}" : $ tokenInfo -> id = T_BRACES_CLOSE ; break ; case "(" : $ tokenInfo -> id = T_PARENTHESIS_OPEN ; break ; case ")" : $ tokenInfo -> id = T_PARENTHESIS_CLOSE ; break ; case "," : $ tokenInfo -> id = T_COMMA ; break ; case "=" : $ tokenInfo -> id = T_EQUAL ; break ; case "." : $ tokenInfo -> id = T_CONCAT ; break ; case ":" : $ tokenInfo -> id = T_COLON ; break ; case "-" : $ tokenInfo -> id = T_MINUS ; break ; case "+" : $ tokenInfo -> id = T_PLUS ; break ; case ">" : $ tokenInfo -> id = T_IS_GREATER ; break ; case "<" : $ tokenInfo -> id = T_IS_SMALLER ; break ; case "*" : $ tokenInfo -> id = T_MULTIPLY ; break ; case "/" : $ tokenInfo -> id = T_DIVIDE ; break ; case "?" : $ tokenInfo -> id = T_QUESTION_MARK ; break ; case "%" : $ tokenInfo -> id = T_MODULO ; break ; case "!" : $ tokenInfo -> id = T_EXCLAMATION_MARK ; break ; case "&" : $ tokenInfo -> id = T_AMPERSAND ; break ; case "[" : $ tokenInfo -> id = T_SQUARE_BRACKET_OPEN ; break ; case "]" : $ tokenInfo -> id = T_SQUARE_BRACKET_CLOSE ; break ; case "@" : $ tokenInfo -> id = T_AROBAS ; break ; case '"' : $ tokenInfo -> id = T_QUOTE ; break ; case '$' : $ tokenInfo -> id = T_DOLLAR ; break ; default : } } $ this -> newTokens [ ] = $ tokenInfo ; } return $ this -> newTokens ; }
|
Identify the token and enventually split the new lines .
|
51,363
|
private function _getAllTokens ( $ source ) { $ newTokens = array ( ) ; set_error_handler ( 'var_dump' , 0 ) ; @ $ errLastResetUndefinedVar ; restore_error_handler ( ) ; $ tokens = @ token_get_all ( $ source ) ; $ parsingErrors = error_get_last ( ) ; if ( ! empty ( $ parsingErrors ) && $ parsingErrors [ "type" ] === 128 ) { throw new Exception ( $ parsingErrors [ "message" ] ) ; } foreach ( $ tokens as $ token ) { $ isTokenArray = is_array ( $ token ) ; $ tokenID = $ isTokenArray ? $ token [ 0 ] : T_UNKNOWN ; $ tokenText = $ isTokenArray ? $ token [ 1 ] : $ token ; if ( $ this -> shortOpenTagOff && $ tokenID === T_INLINE_HTML ) { $ startPos = strpos ( $ tokenText , SHORT_OPEN_TAG ) ; $ endPos = strpos ( $ tokenText , CLOSE_TAG , $ startPos + strlen ( SHORT_OPEN_TAG ) ) ; while ( strlen ( $ tokenText ) > 2 && $ startPos !== false && $ endPos !== false ) { $ beforeText = substr ( $ tokenText , 0 , $ startPos ) ; $ this -> _identifyTokens ( $ beforeText , $ tokenID ) ; $ openTag = new TokenInfo ( ) ; $ openTag -> id = T_OPEN_TAG ; $ openTag -> text = SHORT_OPEN_TAG ; $ this -> tokenNumber ++ ; $ openTag -> position = $ this -> tokenNumber ; $ openTag -> line = $ this -> lineNumber ; $ this -> newTokens [ ] = $ openTag ; $ inlineText = substr ( $ tokenText , $ startPos + strlen ( SHORT_OPEN_TAG ) , $ endPos - $ startPos ) ; $ inlineText = substr ( $ inlineText , 0 , - strlen ( CLOSE_TAG ) ) ; $ inline = $ this -> _getAllTokens ( OPEN_TAG . " " . $ inlineText ) ; array_shift ( $ inline ) ; $ this -> _identifyTokens ( $ newTokens , $ inline ) ; $ closeTag = new TokenInfo ( ) ; $ closeTag -> id = T_CLOSE_TAG ; $ closeTag -> text = CLOSE_TAG ; $ this -> tokenNumber ++ ; $ closeTag -> position = $ this -> tokenNumber ; $ closeTag -> line = $ this -> lineNumber ; $ this -> newTokens [ ] = $ closeTag ; $ tokenText = substr ( $ tokenText , $ endPos + strlen ( SHORT_OPEN_TAG ) ) ; $ startPos = strpos ( $ tokenText , SHORT_OPEN_TAG ) ; $ endPos = strpos ( $ tokenText , CLOSE_TAG , $ startPos + strlen ( SHORT_OPEN_TAG ) ) ; } } $ this -> _identifyTokens ( $ tokenText , $ tokenID ) ; } return $ this -> newTokens ; }
|
Tokenize a string and separate the newline token .
|
51,364
|
public function findClosingParenthesisPosition ( $ startPos ) { $ pos = $ this -> findNextStringPosition ( '(' , $ startPos ) ; $ parenthesisCount = 1 ; $ pos += 1 ; $ nbTokens = count ( $ this -> tokens ) ; while ( $ parenthesisCount > 0 && $ pos < $ nbTokens ) { $ token = $ this -> peekTokenAt ( $ pos ) ; if ( $ token -> id === T_PARENTHESIS_OPEN ) { $ parenthesisCount += 1 ; } else if ( $ token -> id === T_PARENTHESIS_CLOSE ) { $ parenthesisCount -= 1 ; } $ pos += 1 ; } return $ pos - 1 ; }
|
Find the position of the closing parenthesis corresponding to the current position opening parenthesis .
|
51,365
|
public function isTokenInList ( $ tokenToCheck , $ tokenList ) { foreach ( $ tokenList as $ tokenInList ) { if ( $ this -> checkToken ( $ tokenToCheck , $ tokenInList ) ) { return true ; } } return false ; }
|
Checks if a token is in the type of token list .
|
51,366
|
public function toString ( ) { $ result = "" ; $ result .= "line : " . $ this -> line ; $ result .= ", pos : " . $ this -> position ; $ result .= ", id : " . $ this -> getName ( $ this -> id ) ; $ text = str_replace ( "\r\n" , "\\r\\n" , $ this -> text ) ; $ text = str_replace ( "\r" , "\\r" , $ text ) ; $ text = str_replace ( "\n" , "\\n" , $ text ) ; $ result .= ", text : " . $ text ; return $ result ; }
|
Return a string representation of the token .
|
51,367
|
public function getName ( ) { $ tagNames = array ( T_NEW_LINE => 'T_NEW_LINE' , T_TAB => 'T_TAB' , T_SEMICOLON => 'T_SEMICOLON' , T_BRACES_OPEN => 'T_BRACES_OPEN' , T_BRACES_CLOSE => 'T_BRACES_CLOSE' , T_PARENTHESIS_OPEN => 'T_PARENTHESIS_OPEN' , T_PARENTHESIS_CLOSE => 'T_PARENTHESIS_CLOSE' , T_COMMA => 'T_COMMA' , T_EQUAL => 'T_EQUAL' , T_CONCAT => 'T_CONCAT' , T_COLON => 'T_COLON' , T_MINUS => 'T_MINUS' , T_PLUS => 'T_PLUS' , T_IS_GREATER => 'T_IS_GREATER' , T_IS_SMALLER => 'T_IS_SMALLER' , T_MULTIPLY => 'T_MULTIPLY' , T_DIVIDE => 'T_DIVIDE' , T_QUESTION_MARK => 'T_QUESTION_MARK' , T_MODULO => 'T_MODULO' , T_EXCLAMATION_MARK => 'T_EXCLAMATION_MARK' , T_AMPERSAND => 'T_AMPERSAND' , T_SQUARE_BRACKET_OPEN => 'T_SQUARE_BRACKET_OPEN' , T_SQUARE_BRACKET_CLOSE => 'T_SQUARE_BRACKET_CLOSE' , T_AROBAS => 'T_AROBAS' , T_UNKNOWN => 'T_UNKNOWN' , T_DOLLAR => 'T_DOLLAR' , ) ; if ( isset ( $ tagNames [ $ this -> id ] ) ) { $ result = $ tagNames [ $ this -> id ] ; } else { $ result = token_name ( $ this -> id ) ; } return $ result ; }
|
Return the name of a token including the NEW_LINE one .
|
51,368
|
public function setLang ( $ lang = 'en-us' ) { $ this -> lang = $ lang ; try { $ this -> messages = parse_ini_file ( __DIR__ . '/Lang/' . $ this -> lang . '.ini' ) ; } catch ( Exception $ e ) { throw $ e ; } }
|
Set the language file to use
|
51,369
|
public function customErrorHandler ( $ errno , $ errstr ) { if ( $ this -> _isActive ( 'phpException' ) ) { $ check = 'phpException' ; $ level = $ this -> _config -> getTestLevel ( $ check ) ; if ( $ level === null ) { $ level = WARNING ; } $ message = $ this -> _getMessage ( 'PHP_EXPCEPTION' , $ errstr ) ; $ this -> _writeError ( $ check , $ message , $ this -> lineNumber , $ level ) ; } return false ; }
|
Custom Error Handler .
|
51,370
|
public function processFiles ( $ sources , $ excludes = array ( ) ) { $ this -> _reporter -> start ( ) ; set_error_handler ( array ( $ this , 'customErrorHandler' ) , E_ALL ) ; set_exception_handler ( array ( $ this , 'customErrorHandler' ) ) ; $ this -> _excludeList = $ excludes ; $ files = array ( ) ; foreach ( $ sources as $ src ) { $ roots = explode ( "," , $ src ) ; foreach ( $ roots as $ root ) { $ root = trim ( $ root ) ; $ files = array_merge ( $ files , $ this -> _getAllPhpFiles ( $ root , $ excludes ) ) ; } } if ( $ this -> _lineCountReporter !== null ) { $ this -> _lineCountReporter -> start ( ) ; } foreach ( $ files as $ file ) { if ( is_array ( $ file ) ) { continue ; } if ( $ this -> _displayProgress ) { echo "Processing File: " . $ file . "<br/>" . PHP_EOL ; } $ this -> _reporter -> currentlyProcessing ( $ file ) ; try { $ this -> _processFile ( $ file ) ; } catch ( Exception $ e ) { $ msg = $ this -> _getMessage ( 'PHP_EXPCEPTION' , $ e -> getMessage ( ) ) ; $ this -> _writeError ( 'phpException' , $ msg ) ; } } $ this -> _reporter -> stop ( ) ; if ( $ this -> _lineCountReporter !== null ) { $ this -> _lineCountReporter -> writeTotalCount ( count ( $ files ) , $ this -> _ncssTotalClasses , $ this -> _ncssTotalInterfaces , $ this -> _ncssTotalFunctions , $ this -> _ncssTotalLinesOfCode , $ this -> _ncssTotalPhpdoc , $ this -> _ncssTotalLinesPhpdoc , $ this -> _ncssTotalSingleComment , $ this -> _ncssTotalMultiComment ) ; } if ( $ this -> _lineCountReporter !== null ) { $ this -> _lineCountReporter -> stop ( ) ; } }
|
Calls processFile repeatedly for each PHP file that is encountered .
|
51,371
|
private function _resetValues ( ) { $ this -> lineNumber = 1 ; $ this -> _csLeftParenthesis = 0 ; $ this -> _fcLeftParenthesis = 0 ; $ this -> inDoWhile = false ; $ this -> statementStack = new StatementStack ( ) ; $ this -> _inString = false ; $ this -> _inControlStatement = false ; $ this -> _inFunctionStatement = false ; $ this -> _beforeArrayDeclaration = false ; $ this -> _inFunction = false ; $ this -> _privateFunctions = array ( ) ; $ this -> _usedFunctions = array ( ) ; $ this -> _variables = array ( ) ; $ this -> _privateFunctionsStartLines = array ( ) ; $ this -> _inFuncCall = false ; $ this -> _nbFunctionParameters = 0 ; $ this -> _justAfterFuncStmt = false ; $ this -> _justAfterControlStmt = false ; $ this -> _functionStartLine = 0 ; $ this -> _functionReturns = false ; $ this -> _functionThrows = false ; $ this -> _functionVisibility = 'PUBLIC' ; $ this -> _functionStatic = false ; $ this -> _currentStatement = false ; $ this -> _inClassStatement = false ; $ this -> _inInterfaceStatement = false ; $ this -> __constantDef = false ; $ this -> _ncssFileClasses = 0 ; $ this -> _ncssFileInterfaces = 0 ; $ this -> _ncssFileFunctions = 0 ; $ this -> _ncssFileLinesOfCode = 0 ; $ this -> _ncssFilePhpdoc = 0 ; $ this -> _ncssFileLinesPhpdoc = 0 ; $ this -> _ncssFileSingleComment = 0 ; $ this -> _ncssFileMultiComment = 0 ; $ this -> _currentFunctionName = null ; $ this -> _currentClassname = null ; $ this -> _currentInterfacename = null ; $ this -> _currentFilename = null ; $ this -> _packageName = null ; $ this -> _isView = false ; $ this -> _isModel = false ; $ this -> _isController = false ; $ this -> _isClass = false ; $ this -> _isLineStart = true ; }
|
Reset the state of the different flags .
|
51,372
|
private function _processFile ( $ filename ) { if ( $ this -> debug ) { echo "Processing File : " . $ filename . PHP_EOL ; } $ this -> tokenizer -> reset ( ) ; $ this -> _resetValues ( ) ; if ( stripos ( $ filename , 'view' ) !== false || stripos ( $ filename , 'layouts' ) !== false ) { $ this -> _isView = true ; } elseif ( stripos ( $ filename , 'model' ) !== false ) { $ this -> _isModel = true ; } elseif ( stripos ( $ filename , 'controller' ) !== false ) { $ this -> _isController = true ; } elseif ( stripos ( $ filename , 'class' ) !== false ) { $ this -> _isClass = true ; } $ this -> _currentFilename = $ filename ; $ this -> _packageName = $ this -> _extractPackageName ( $ filename ) ; $ this -> tokenizer -> tokenize ( $ filename ) ; if ( $ this -> tokenizer -> getTokenNumber ( ) === 0 ) { $ this -> _checkEmptyFile ( $ filename ) ; return ; } $ token = $ this -> tokenizer -> getCurrentToken ( ) ; $ this -> _processFileStart ( ) ; while ( $ token !== false ) { $ this -> _processToken ( $ token ) ; $ this -> lineNumber = $ token -> line ; $ token = $ this -> tokenizer -> getNextToken ( ) ; } if ( $ this -> _isActive ( 'noFileCloseTag' ) ) { if ( $ this -> tokenizer -> checkPreviousToken ( T_CLOSE_TAG ) ) { $ this -> _writeError ( 'noFileCloseTag' , $ this -> _getMessage ( 'END_FILE_CLOSE_TAG' ) ) ; } } if ( $ this -> _isActive ( 'noFileFinishHTML' ) && ! $ this -> _isView ) { if ( $ this -> tokenizer -> checkPreviousToken ( T_INLINE_HTML ) ) { $ this -> _writeError ( 'noFileFinishHTML' , $ this -> _getMessage ( 'END_FILE_INLINE_HTML' ) ) ; } } $ this -> _checkUnusedPrivateFunctions ( ) ; $ this -> _checkUnusedVariables ( ) ; if ( $ this -> _ncssFileClasses > 0 || $ this -> _ncssFileInterfaces > 0 ) { $ this -> _checkFileNaming ( ) ; } if ( $ this -> _lineCountReporter !== null ) { $ this -> _lineCountReporter -> writeFileCount ( $ this -> _packageName , $ this -> _ncssFileClasses , $ this -> _ncssFileInterfaces , $ this -> _ncssFileFunctions , $ this -> _ncssFileLinesOfCode , $ this -> _ncssFilePhpdoc , $ this -> _ncssFileLinesPhpdoc , $ this -> _ncssFileSingleComment , $ this -> _ncssFileMultiComment ) ; } $ this -> _fileSuppressWarnings = array ( ) ; $ this -> _classSuppressWarnings = array ( ) ; $ this -> _interfaceSuppressWarnings = array ( ) ; }
|
Process one php file .
|
51,373
|
private function _getAllPhpFiles ( $ src , $ excludes , $ dir = '' ) { $ files = array ( ) ; if ( ! is_dir ( $ src ) ) { $ isExcluded = false ; foreach ( $ excludes as $ patternExcluded ) { if ( strstr ( $ src , $ patternExcluded ) ) { $ isExcluded = true ; } } if ( ! $ isExcluded ) { $ files [ ] = $ src ; } } else { $ root = opendir ( $ src ) ; if ( $ root ) { while ( $ file = readdir ( $ root ) ) { if ( $ this -> _inArray ( $ file , $ this -> ignoredFiles ) ) { continue ; } $ fullPath = $ src . "/" . $ file ; $ isExcluded = false ; foreach ( $ excludes as $ patternExcluded ) { if ( strstr ( $ fullPath , $ patternExcluded ) ) { $ isExcluded = true ; } } if ( ! $ isExcluded ) { if ( is_dir ( $ src . "/" . $ file ) ) { $ filesToMerge = $ this -> _getAllPhpFiles ( $ src . "/" . $ file , $ excludes , $ dir . '/' . $ file ) ; $ files = array_merge ( $ files , $ filesToMerge ) ; } else { $ pathParts = pathinfo ( $ file ) ; if ( array_key_exists ( 'extension' , $ pathParts ) ) { if ( in_array ( $ pathParts [ 'extension' ] , $ this -> validExtensions ) ) { $ files [ ] = realpath ( $ src . "/" . $ file ) ; } } } } } } } return $ files ; }
|
Go through a directory recursively and get all the PHP files . Ignores files or subdirectories that are in the _excludeList
|
51,374
|
private function _checkProhibitedTokens ( $ token ) { if ( $ this -> _isActive ( 'checkProhibitedTokens' ) ) { if ( in_array ( $ token -> getName ( ) , $ this -> _prohibitedTokens ) ) { $ msg = $ this -> _getMessage ( "PROHIBITED_TOKEN" , $ token -> getName ( ) ) ; $ this -> _writeError ( 'checkProhibitedTokens' , $ msg ) ; } } }
|
Check for the presence of a prohibited token .
|
51,375
|
private function _checkProhibitedKeywordsRegex ( $ token ) { if ( $ this -> _isActive ( 'checkProhibitedKeywordsRegex' ) ) { foreach ( $ this -> _prohibitedKeywordsRegex as $ pattern ) { preg_match_all ( $ pattern , $ token -> text , $ matches ) ; $ matches = $ matches [ 0 ] ; if ( ! empty ( $ matches ) ) { foreach ( $ matches as $ key => $ value ) { $ msg = $ this -> _getMessage ( 'PROHIBITED_KEYWORD_REGEX' , $ value ) ; $ this -> _writeError ( 'checkProhibitedKeywordsRegex' , $ msg ) ; } } } } }
|
Check for the presence of a text corresponding to a prohibited regexp .
|
51,376
|
private function _processSquareBracketOpen ( $ token ) { if ( $ this -> tokenizer -> checkPreviousValidToken ( T_EQUAL ) ) { $ stackitem = new StatementItem ( ) ; $ stackitem -> line = $ token -> line ; $ stackitem -> type = 'ARRAY' ; $ stackitem -> name = 'square_bracket_open' ; $ this -> statementStack -> push ( $ stackitem ) ; } }
|
Launched when a [ is encountered .
|
51,377
|
private function _processSquareBracketClose ( $ token ) { if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_ARRAY && $ this -> statementStack -> getCurrentStackItem ( ) -> name === 'square_bracket_open' ) { $ this -> statementStack -> pop ( ) ; } }
|
Launched when a ] is encountered .
|
51,378
|
private function _processParenthesisOpen ( $ token ) { if ( $ this -> _inFuncCall ) { $ this -> _fcLeftParenthesis += 1 ; } elseif ( $ this -> _inControlStatement || $ this -> _inFunctionStatement ) { $ this -> _csLeftParenthesis += 1 ; } if ( $ this -> _beforeArrayDeclaration ) { $ stackitem = new StatementItem ( ) ; $ stackitem -> line = $ token -> line ; $ stackitem -> type = 'ARRAY' ; $ stackitem -> name = 'ARRAY' ; $ this -> statementStack -> push ( $ stackitem ) ; $ this -> _beforeArrayDeclaration = false ; } $ this -> statementStack -> getCurrentStackItem ( ) -> openParentheses += 1 ; }
|
Launched when a ( sign is encountered .
|
51,379
|
private function _processParenthesisClose ( $ token ) { $ this -> statementStack -> getCurrentStackItem ( ) -> openParentheses -= 1 ; if ( $ this -> _inFuncCall ) { $ this -> _fcLeftParenthesis -= 1 ; } elseif ( $ this -> _inControlStatement || $ this -> _inFunctionStatement ) { $ this -> _csLeftParenthesis -= 1 ; } if ( $ this -> _fcLeftParenthesis === 0 ) { $ this -> _inFuncCall = false ; array_pop ( $ this -> _currentFuncCall ) ; } if ( $ this -> _csLeftParenthesis === 0 ) { if ( $ this -> _inControlStatement ) { $ this -> _inControlStatement = false ; $ this -> _justAfterControlStmt = true ; $ this -> _checkNeedBraces ( ) ; } elseif ( $ this -> _inFunctionStatement && ! $ this -> _inInterface ) { $ this -> _inFunctionStatement = false ; $ this -> _justAfterFuncStmt = true ; } } if ( $ this -> statementStack -> getCurrentStackItem ( ) -> openParentheses === 0 ) { if ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_ARRAY && $ this -> statementStack -> getCurrentStackItem ( ) -> name !== 'square_bracket_open' ) { $ this -> statementStack -> pop ( ) ; } } }
|
Launched when a ) sign is encountered .
|
51,380
|
private function _processMinus ( $ token ) { if ( ! $ this -> _inFuncCall ) { $ this -> _checkWhiteSpaceBefore ( $ token -> text ) ; } if ( ! ( $ this -> tokenizer -> checkNextToken ( T_LNUMBER ) || $ this -> tokenizer -> checkNextToken ( T_DNUMBER ) ) ) { $ this -> _checkWhiteSpaceAfter ( $ token -> text ) ; } }
|
Launched when a minus sign is encountered .
|
51,381
|
private function _processSemiColon ( $ token ) { $ this -> _checkNoWhiteSpaceBefore ( $ token -> text ) ; $ this -> _checkEmptyStatement ( ) ; if ( $ this -> statementStack -> getCurrentStackItem ( ) -> noCurly === true ) { $ this -> statementStack -> pop ( ) ; } }
|
Launched when a semicolon is encountered .
|
51,382
|
private function _processBracesOpen ( $ token ) { if ( $ this -> _config -> getTestProperty ( 'funcDefinitionOpenCurly' , 'position' ) === SAME_LINE ) { $ this -> _checkWhiteSpaceBefore ( $ token -> text ) ; } $ stackitem = new StatementItem ( ) ; $ stackitem -> line = $ token -> line ; if ( $ this -> _justAfterFuncStmt ) { $ this -> _processFunctionStart ( ) ; $ stackitem -> type = "FUNCTION" ; $ stackitem -> name = $ this -> _currentFunctionName ; $ stackitem -> visibility = $ this -> _functionVisibility ; } else if ( $ this -> _justAfterControlStmt ) { $ this -> _processControlStatementStart ( ) ; $ stackitem -> type = strtoupper ( $ this -> _currentStatement ) ; } else if ( $ this -> _inClassStatement ) { $ this -> _inClassStatement = false ; $ this -> _processClassStart ( ) ; $ stackitem -> type = "CLASS" ; $ stackitem -> name = $ this -> _currentClassname ; } else if ( $ this -> _inInterfaceStatement ) { $ this -> _inInterfaceStatement = false ; $ this -> _processInterfaceStart ( ) ; $ stackitem -> type = "INTERFACE" ; $ stackitem -> name = $ this -> _currentInterfacename ; } else { $ stackitem -> type = "{" ; } $ this -> _checkEmptyBlock ( ) ; $ this -> statementStack -> push ( $ stackitem ) ; }
|
Launched when an opening brace is encountered .
|
51,383
|
private function _processBracesClose ( $ token ) { if ( $ this -> _isActive ( 'controlCloseCurly' ) && ! ( $ this -> _isView ) && ! ( $ this -> _inString ) ) { $ previousToken = $ this -> tokenizer -> peekPrvsValidToken ( ) ; if ( ( $ previousToken -> line === $ token -> line ) && ( $ previousToken -> id !== T_BRACES_OPEN ) ) { $ this -> _writeError ( 'controlCloseCurly' , $ this -> _getMessage ( "END_BLOCK_NEW_LINE" ) ) ; } } $ currentStackItem = $ this -> statementStack -> getCurrentStackItem ( ) ; if ( ! is_String ( $ currentStackItem ) ) { if ( $ currentStackItem -> type === StatementItem :: TYPE_SWITCH || $ currentStackItem -> type === StatementItem :: TYPE_DEFAULT || $ currentStackItem -> type === StatementItem :: TYPE_CASE ) { $ this -> _processSwitchStop ( ) ; } if ( $ currentStackItem -> type === StatementItem :: TYPE_FUNCTION ) { $ this -> _processFunctionStop ( ) ; } if ( $ currentStackItem -> type === StatementItem :: TYPE_CLASS ) { $ this -> _processClassStop ( ) ; } if ( $ currentStackItem -> type === StatementItem :: TYPE_INTERFACE ) { $ this -> _processInterfaceStop ( ) ; } } $ this -> statementStack -> pop ( ) ; $ isElse = ( $ currentStackItem -> type === StatementItem :: TYPE_ELSE ) ; $ isIf = ( $ this -> statementStack -> getCurrentStackItem ( ) -> type === StatementItem :: TYPE_IF ) ; $ isNoCurly = $ this -> statementStack -> getCurrentStackItem ( ) -> noCurly ; if ( $ isElse && $ isIf && $ isNoCurly ) { $ this -> statementStack -> pop ( ) ; } }
|
Launched when a closing brace is encountered .
|
51,384
|
private function _countLinesOfCode ( ) { $ currentToken = $ this -> tokenizer -> getCurrentToken ( ) ; $ previousToken = $ this -> tokenizer -> peekPrvsValidToken ( ) ; if ( $ previousToken !== null ) { if ( ! $ this -> tokenizer -> checkToken ( $ previousToken , T_NEW_LINE ) && ( $ previousToken -> line === $ currentToken -> line ) ) { $ this -> _ncssTotalLinesOfCode ++ ; $ this -> _ncssFileLinesOfCode ++ ; } } }
|
Check if the current line if a line of code and if it s the case increment the count .
|
51,385
|
private function _checkConstantNaming ( $ text ) { if ( $ this -> _isActive ( 'constantNaming' ) ) { $ text = ltrim ( $ text , "\"'" ) ; $ text = rtrim ( $ text , "\"'" ) ; $ ret = preg_match ( $ this -> _config -> getTestRegExp ( 'constantNaming' ) , $ text ) ; if ( ! $ ret ) { $ msg = $ this -> _getMessage ( 'CONSTANT_NAMING' , $ text , $ this -> _config -> getTestRegExp ( 'constantNaming' ) ) ; $ this -> _writeError ( 'constantNaming' , $ msg ) ; } } $ this -> _constantDef = false ; }
|
Checks to see if the constant follows the naming convention .
|
51,386
|
private function _checkVariableNaming ( $ text ) { if ( $ this -> _inClass || $ this -> _inInterface ) { if ( $ this -> _inFunctionStatement || $ this -> _inInterfaceStatement ) { $ this -> _checkScopedVariableNaming ( $ text , 'functionParameterNaming' , 'FUNCTION_PARAMETER_NAMING' ) ; } else if ( $ this -> _inFunction ) { if ( array_key_exists ( $ text , $ this -> _functionParameters ) ) { $ this -> _checkScopedVariableNaming ( $ text , 'functionParameterNaming' , 'FUNCTION_PARAMETER_NAMING' ) ; } else { $ this -> _checkScopedVariableNaming ( $ text , 'localVariableNaming' , 'LOCAL_VARIABLE_NAMING' ) ; } } else { $ this -> _checkScopedVariableNaming ( $ text , 'memberVariableNaming' , 'MEMBER_VARIABLE_NAMING' ) ; } } else { $ this -> _checkScopedVariableNaming ( $ text , 'topLevelVariableNaming' , 'TOPLEVEL_VARIABLE_NAMING' ) ; } }
|
Checks to see if the variable follows the naming convention .
|
51,387
|
private function _checkScopedVariableNaming ( $ variableText , $ ruleName , $ msgName ) { if ( $ this -> _isActive ( $ ruleName ) || $ this -> _isActive ( 'variableNaming' ) ) { $ texttoTest = ltrim ( $ variableText , "\"'" ) ; $ texttoTest = rtrim ( $ texttoTest , "\"'" ) ; if ( strpos ( $ texttoTest , "$" ) === 0 ) { $ texttoTest = substr ( $ texttoTest , 1 ) ; } if ( ! $ this -> _config -> isException ( $ ruleName , $ texttoTest ) ) { if ( $ this -> _isActive ( $ ruleName ) ) { $ ret = preg_match ( $ this -> _config -> getTestRegExp ( $ ruleName ) , $ texttoTest ) ; } else { $ ret = preg_match ( $ this -> _config -> getTestRegExp ( 'variableNaming' ) , $ texttoTest ) ; } if ( ! $ ret ) { if ( $ this -> _isActive ( $ ruleName ) ) { $ msg = $ this -> _getMessage ( $ msgName , $ variableText , $ this -> _config -> getTestRegExp ( $ ruleName ) ) ; } else { $ msg = $ this -> _getMessage ( 'VARIABLE_NAMING' , $ variableText , $ this -> _config -> getTestRegExp ( 'variableNaming' ) ) ; } $ this -> _writeError ( $ ruleName , $ msg ) ; } } } }
|
Utility function to check the naming of a variable given its scope rule and message .
|
51,388
|
private function _checkFunctionNaming ( $ text ) { if ( $ this -> _isActive ( 'functionNaming' ) ) { $ ret = preg_match ( $ this -> _config -> getTestRegExp ( 'functionNaming' ) , $ text ) ; if ( ! $ ret ) { $ msg = $ this -> _getMessage ( 'FUNCNAME_NAMING' , $ text , $ this -> _config -> getTestRegExp ( 'functionNaming' ) ) ; $ this -> _writeError ( 'functionNaming' , $ msg ) ; } } }
|
Check the naming of a function .
|
51,389
|
private function _checkFileNaming ( ) { if ( $ this -> _isActive ( 'fileNaming' ) ) { $ fileBaseName = basename ( $ this -> _currentFilename ) ; $ ret = preg_match ( $ this -> _config -> getTestRegExp ( 'fileNaming' ) , $ fileBaseName ) ; if ( ! $ ret ) { $ msg = $ this -> _getMessage ( 'FILENAME_NAMING' , $ fileBaseName , $ this -> _config -> getTestRegExp ( 'fileNaming' ) ) ; $ this -> _writeError ( 'fileNaming' , $ msg ) ; } } }
|
Check the naming of a file .
|
51,390
|
private function _checkTypeNameFileNameMatch ( $ typeName ) { $ fileBaseName = basename ( $ this -> _currentFilename ) ; if ( $ this -> _isActive ( 'typeNameMatchesFileName' ) && ! ( substr ( $ fileBaseName , 0 , strlen ( $ typeName ) + 1 ) === $ typeName . "." ) ) { $ msg = $ this -> _getMessage ( 'TYPE_FILE_NAME_MISMATCH' , $ typeName , $ fileBaseName ) ; $ this -> _writeError ( 'typeNameMatchesFileName' , $ msg ) ; } }
|
Check that the type name matches the file name .
|
51,391
|
private function _processFunctionCall ( $ text ) { if ( strtolower ( $ text ) === "define" ) { $ this -> _constantDef = true ; } if ( $ this -> tokenizer -> checkNextValidToken ( T_PARENTHESIS_OPEN ) ) { $ this -> _inFuncCall = true ; array_push ( $ this -> _currentFuncCall , $ text ) ; $ this -> _usedFunctions [ $ text ] = $ text ; $ isObjectCall = $ this -> tokenizer -> checkPreviousToken ( T_OBJECT_OPERATOR ) ; if ( ! $ isObjectCall ) { $ this -> _checkProhibitedFunctions ( $ text ) ; $ this -> _checkDeprecation ( $ text ) ; $ this -> _checkAliases ( $ text ) ; $ this -> _checkReplacements ( $ text ) ; } $ this -> _checkSilenced ( $ text ) ; if ( $ this -> _isActive ( 'noSpaceAfterFunctionName' ) ) { if ( ! $ this -> tokenizer -> checkNextToken ( T_PARENTHESIS_OPEN ) ) { $ msg = $ this -> _getMessage ( 'NO_SPACE_AFTER_TOKEN' , $ text ) ; $ this -> _writeError ( 'noSpaceAfterFunctionName' , $ msg ) ; } } } if ( $ this -> _isActive ( 'functionInsideLoop' ) ) { if ( ( strtolower ( $ text ) === 'count' || strtolower ( $ text ) === 'sizeof' ) && $ this -> _inControlStatement ) { $ loops = array ( 'do' , 'while' , 'for' , 'foreach' ) ; if ( in_array ( $ this -> _currentStatement , $ loops ) ) { $ msg = $ this -> _getMessage ( 'FUNCTION_INSIDE_LOOP' , strtolower ( $ text ) ) ; $ this -> _writeError ( 'functionInsideLoop' , $ msg ) ; } } } }
|
Check the validity of a function call .
|
51,392
|
private function _processInterfaceStart ( ) { $ this -> _inInterface = true ; $ this -> _interfaceLevel = $ this -> statementStack -> count ( ) ; if ( $ this -> _isActive ( 'interfaceOpenCurly' ) ) { $ pos = $ this -> _config -> getTestProperty ( 'interfaceOpenCurly' , 'position' ) ; $ currentToken = $ this -> tokenizer -> getCurrentToken ( ) ; $ previousToken = $ this -> tokenizer -> peekPrvsValidToken ( ) ; if ( $ pos === NEW_LINE ) { $ isPosOk = ( $ previousToken -> line < $ currentToken -> line ) ; } else { $ isPosOk = ( $ previousToken -> line === $ currentToken -> line ) ; } if ( ! $ isPosOk ) { $ tmp = ( $ pos === SAME_LINE ) ? "the previous line." : "a new line." ; $ msg = $ this -> _getMessage ( 'LEFT_CURLY_POS' , $ tmp ) ; $ this -> _writeError ( 'interfaceOpenCurly' , $ msg ) ; } } }
|
Process the start of a interface .
|
51,393
|
private function _processClassStart ( ) { $ this -> _inClass = true ; $ this -> _classLevel = $ this -> statementStack -> count ( ) ; if ( $ this -> _isActive ( 'classOpenCurly' ) ) { $ pos = $ this -> _config -> getTestProperty ( 'classOpenCurly' , 'position' ) ; $ currentToken = $ this -> tokenizer -> getCurrentToken ( ) ; $ previousToken = $ this -> tokenizer -> peekPrvsValidToken ( ) ; if ( $ pos === NEW_LINE ) { $ isPosOk = ( $ previousToken -> line < $ currentToken -> line ) ; } else { $ isPosOk = ( $ previousToken -> line === $ currentToken -> line ) ; } if ( ! $ isPosOk ) { $ tmp = ( $ pos === SAME_LINE ) ? "the previous line." : "a new line." ; $ msg = $ this -> _getMessage ( 'LEFT_CURLY_POS' , $ tmp ) ; $ this -> _writeError ( 'classOpenCurly' , $ msg ) ; } } }
|
Process the start of a class .
|
51,394
|
private function _processFunctionStart ( ) { $ this -> _inFunction = true ; $ this -> _cyclomaticComplexity = 1 ; $ this -> _npathComplexity = 0 ; $ this -> _functionLevel = $ this -> statementStack -> count ( ) ; $ this -> _justAfterFuncStmt = false ; $ this -> _functionStartLine = $ this -> lineNumber ; if ( $ this -> _isActive ( 'funcDefinitionOpenCurly' ) ) { $ pos = $ this -> _config -> getTestProperty ( 'funcDefinitionOpenCurly' , 'position' ) ; $ currentToken = $ this -> tokenizer -> getCurrentToken ( ) ; $ previousToken = $ this -> tokenizer -> peekPrvsValidToken ( ) ; if ( $ pos === NEW_LINE ) { $ isPosOk = ( $ previousToken -> line < $ currentToken -> line ) ; } else { $ isPosOk = ( $ previousToken -> line === $ currentToken -> line ) ; } if ( ! $ isPosOk ) { $ tmp = ( $ pos === SAME_LINE ) ? "the previous line." : "a new line." ; $ msg = $ this -> _getMessage ( 'LEFT_CURLY_POS' , $ tmp ) ; $ this -> _writeError ( 'funcDefinitionOpenCurly' , $ msg ) ; } } }
|
Process the start of a function .
|
51,395
|
private function _checkCyclomaticComplexity ( ) { if ( $ this -> _isActive ( 'cyclomaticComplexity' ) ) { $ warningLevel = $ this -> _config -> getTestProperty ( 'cyclomaticComplexity' , 'warningLevel' ) ; $ errorLevel = $ this -> _config -> getTestProperty ( 'cyclomaticComplexity' , 'errorLevel' ) ; $ msg = $ this -> _getMessage ( 'CYCLOMATIC_COMPLEXITY' , $ this -> _currentFunctionName , $ this -> _cyclomaticComplexity , $ warningLevel ) ; if ( $ this -> _cyclomaticComplexity > $ warningLevel ) { $ this -> _writeError ( 'cyclomaticComplexity' , $ msg , $ this -> _functionStartLine , WARNING ) ; } else if ( $ this -> _cyclomaticComplexity > $ errorLevel ) { $ this -> _writeError ( 'cyclomaticComplexity' , $ msg , $ this -> _functionStartLine , ERROR ) ; } } }
|
Check the cyclomatic complexity of a function .
|
51,396
|
private function _checkNPathComplexity ( ) { if ( $ this -> _isActive ( 'npathComplexity' ) ) { $ warningLevel = $ this -> _config -> getTestProperty ( 'npathComplexity' , 'warningLevel' ) ; $ errorLevel = $ this -> _config -> getTestProperty ( 'npathComplexity' , 'errorLevel' ) ; $ msg = $ this -> _getMessage ( 'NPATH_COMPLEXITY' , $ this -> _currentFunctionName , $ this -> _npathComplexity , $ warningLevel ) ; if ( $ this -> _npathComplexity > $ warningLevel ) { $ this -> _writeError ( 'npathComplexity' , $ msg , $ this -> _functionStartLine , WARNING ) ; } else if ( $ this -> _npathComplexity > $ errorLevel ) { $ this -> _writeError ( 'npathComplexity' , $ msg , $ this -> _functionStartLine , ERROR ) ; } } }
|
Check the NPath complexity of a function .
|
51,397
|
private function _checkDocBlockParameters ( ) { $ isAnonymous = $ this -> statementStack -> getCurrentStackItem ( ) -> visibility === 'ANONYMOUS' ; if ( $ this -> _isActive ( 'docBlocks' ) && ! $ isAnonymous && ! $ this -> _config -> isException ( 'docBlocks' , $ this -> _currentFunctionName ) && ! $ this -> statementStack -> getParentStackItem ( ) -> docblocInheritDoc ) { $ isPrivateExcluded = $ this -> _config -> getTestProperty ( 'docBlocks' , 'excludePrivateMembers' ) ; if ( ! ( $ isPrivateExcluded && $ this -> _functionVisibility === 'PRIVATE' ) ) { if ( ( $ this -> _config -> getTestProperty ( 'docBlocks' , 'testReturn' ) !== 'false' ) ) { if ( $ this -> _functionReturns && ( $ this -> statementStack -> getParentStackItem ( ) -> docblocNbReturns === 0 ) ) { $ msg = $ this -> _getMessage ( 'DOCBLOCK_RETURN' , $ this -> _currentFunctionName ) ; $ this -> _writeError ( 'docBlocks' , $ msg ) ; } } if ( ( $ this -> _config -> getTestProperty ( 'docBlocks' , 'testParam' ) !== 'false' ) ) { if ( $ this -> _nbFunctionParameters !== $ this -> statementStack -> getParentStackItem ( ) -> docblocNbParams ) { $ msg = $ this -> _getMessage ( 'DOCBLOCK_PARAM' , $ this -> _currentFunctionName ) ; $ this -> _writeError ( 'docBlocks' , $ msg ) ; } } if ( ( $ this -> _config -> getTestProperty ( 'docBlocks' , 'testThrow' ) !== 'false' ) ) { if ( $ this -> _functionThrows && ( $ this -> statementStack -> getParentStackItem ( ) -> docblocNbThrows === 0 ) ) { $ msg = $ this -> _getMessage ( 'DOCBLOCK_THROW' , $ this -> _currentFunctionName ) ; $ this -> _writeError ( 'docBlocks' , $ msg ) ; } } } } }
|
Check that the declared parameters in the docblock match the content of the function .
|
51,398
|
private function _checkFunctionLength ( ) { if ( $ this -> _isActive ( 'functionLength' ) ) { $ functionLength = $ this -> lineNumber - $ this -> _functionStartLine ; $ maxLength = $ this -> _config -> getTestProperty ( 'functionLength' , 'maxLength' ) ; if ( $ functionLength > $ maxLength ) { $ msg = $ this -> _getMessage ( 'FUNCTION_LENGTH_THROW' , $ this -> _currentFunctionName , $ functionLength , $ maxLength ) ; $ this -> _writeError ( 'docBlocks' , $ msg ) ; } } }
|
Check the length of the function .
|
51,399
|
private function _processFunctionStop ( ) { $ this -> _inFunction = false ; $ this -> _checkCyclomaticComplexity ( ) ; $ this -> _checkNPathComplexity ( ) ; $ this -> _checkDocBlockParameters ( ) ; $ this -> _checkFunctionLength ( ) ; $ this -> _checkUnusedFunctionParameters ( ) ; $ this -> _functionSuppressWarnings = array ( ) ; $ this -> statementStack -> getParentStackItem ( ) -> docblocNbParams = 0 ; $ this -> statementStack -> getParentStackItem ( ) -> docblocNbReturns = 0 ; $ this -> statementStack -> getParentStackItem ( ) -> docblocNbThrows = 0 ; $ this -> statementStack -> getParentStackItem ( ) -> docblocInheritDoc = false ; }
|
Process the end of a function declaration .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.