idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
36,500 | public function convertToDatabaseValue ( $ value , AbstractPlatform $ platform ) { if ( ! $ value ) { return null ; } if ( $ platform instanceof MySqlPlatform ) { $ format = "POINT(%F %F)" ; } else { $ format = "(%F, %F)" ; } return sprintf ( $ format , $ value -> getLatitude ( ) , $ value -> getLongitude ( ) ) ; } | Converts PHP representation to the SQL value . |
36,501 | public function logChangeSet ( LifecycleEventArgs $ eventArgs ) { $ em = $ eventArgs -> getEntityManager ( ) ; $ uow = $ em -> getUnitOfWork ( ) ; $ entity = $ eventArgs -> getEntity ( ) ; $ classMetadata = $ em -> getClassMetadata ( get_class ( $ entity ) ) ; if ( $ this -> isEntitySupported ( $ classMetadata -> reflC... | Logs entity changeset |
36,502 | public function generateSlug ( ) { if ( $ this -> getRegenerateSlugOnUpdate ( ) || empty ( $ this -> slug ) ) { $ fields = $ this -> getSluggableFields ( ) ; $ values = [ ] ; foreach ( $ fields as $ field ) { if ( property_exists ( $ this , $ field ) ) { $ val = $ this -> { $ field } ; } else { $ methodName = 'get' . u... | Generates and sets the entity s slug . Called prePersist and preUpdate |
36,503 | private function isSortable ( ClassMetadata $ classMetadata ) { return $ this -> getClassAnalyzer ( ) -> hasTrait ( $ classMetadata -> reflClass , $ this -> sortableTrait , $ this -> isRecursive ) ; } | Checks if entity is a sortable |
36,504 | public function loadClassMetadata ( LoadClassMetadataEventArgs $ eventArgs ) { $ classMetadata = $ eventArgs -> getClassMetadata ( ) ; if ( null === $ classMetadata -> reflClass ) { return ; } if ( $ this -> isBlameable ( $ classMetadata ) ) { $ this -> mapEntity ( $ classMetadata ) ; } } | Adds metadata about how to store user either a string or an ManyToOne association on user entity |
36,505 | public function prePersist ( LifecycleEventArgs $ eventArgs ) { $ em = $ eventArgs -> getEntityManager ( ) ; $ uow = $ em -> getUnitOfWork ( ) ; $ entity = $ eventArgs -> getEntity ( ) ; $ classMetadata = $ em -> getClassMetadata ( get_class ( $ entity ) ) ; if ( $ this -> isBlameable ( $ classMetadata ) ) { if ( ! $ e... | Stores the current user into createdBy and updatedBy properties |
36,506 | public function preUpdate ( LifecycleEventArgs $ eventArgs ) { $ em = $ eventArgs -> getEntityManager ( ) ; $ uow = $ em -> getUnitOfWork ( ) ; $ entity = $ eventArgs -> getEntity ( ) ; $ classMetadata = $ em -> getClassMetadata ( get_class ( $ entity ) ) ; if ( $ this -> isBlameable ( $ classMetadata ) ) { if ( ! $ en... | Stores the current user into updatedBy property |
36,507 | public function preRemove ( LifecycleEventArgs $ eventArgs ) { $ em = $ eventArgs -> getEntityManager ( ) ; $ uow = $ em -> getUnitOfWork ( ) ; $ entity = $ eventArgs -> getEntity ( ) ; $ classMetadata = $ em -> getClassMetadata ( get_class ( $ entity ) ) ; if ( $ this -> isBlameable ( $ classMetadata ) ) { if ( ! $ en... | Stores the current user into deletedBy property |
36,508 | private function isBlameable ( ClassMetadata $ classMetadata ) { return $ this -> getClassAnalyzer ( ) -> hasTrait ( $ classMetadata -> reflClass , $ this -> blameableTrait , $ this -> isRecursive ) ; } | Checks if entity is blameable |
36,509 | public function loadClassMetadata ( LoadClassMetadataEventArgs $ eventArgs ) { $ classMetadata = $ eventArgs -> getClassMetadata ( ) ; if ( null === $ classMetadata -> reflClass ) { return ; } if ( $ this -> isTranslatable ( $ classMetadata ) ) { $ this -> mapTranslatable ( $ classMetadata ) ; } if ( $ this -> isTransl... | Adds mapping to the translatable and translations . |
36,510 | private function convertFetchString ( $ fetchMode ) { if ( is_int ( $ fetchMode ) ) return $ fetchMode ; switch ( $ fetchMode ) { case "LAZY" : return ClassMetadataInfo :: FETCH_LAZY ; case "EAGER" : return ClassMetadataInfo :: FETCH_EAGER ; case "EXTRA_LAZY" : return ClassMetadataInfo :: FETCH_EXTRA_LAZY ; default : r... | Convert string FETCH mode to required string |
36,511 | private function isTranslatable ( ClassMetadata $ classMetadata ) { return $ this -> getClassAnalyzer ( ) -> hasTrait ( $ classMetadata -> reflClass , $ this -> translatableTrait ) ; } | Checks if entity is translatable |
36,512 | private function isTranslation ( ClassMetadata $ classMetadata ) { return $ this -> getClassAnalyzer ( ) -> hasTrait ( $ classMetadata -> reflClass , $ this -> translationTrait ) ; } | Checks if entity is a translation |
36,513 | private function isTreeNode ( ClassMetadata $ classMetadata ) { return $ this -> getClassAnalyzer ( ) -> hasTrait ( $ classMetadata -> reflClass , $ this -> nodeTrait , $ this -> isRecursive ) ; } | Checks if entity is a tree |
36,514 | protected function injectMethod ( ClassReflection $ class , $ methodTag ) { $ data = $ this -> parseMethod ( $ methodTag ) ; if ( ! $ data ) { return false ; } $ method = new MethodReflection ( $ data [ 'name' ] , $ class -> getLine ( ) ) ; $ method -> setDocComment ( $ data [ 'description' ] ) ; $ method -> setShortDe... | Adds a new method to the class using an array of tokens . |
36,515 | public function loadClass ( $ name ) { $ name = ltrim ( $ name , '\\' ) ; if ( $ this -> getClass ( $ name ) instanceof LazyClassReflection ) { try { $ this -> addClass ( $ this -> store -> readClass ( $ this , $ name ) ) ; } catch ( \ InvalidArgumentException $ e ) { return ; } } return $ this -> classes [ $ name ] ; ... | this must only be used in LazyClassReflection to get the right values |
36,516 | protected function injectProperty ( ClassReflection $ class , array $ propertyTag ) { if ( count ( $ propertyTag ) == 3 && ! empty ( $ propertyTag [ 1 ] ) ) { $ property = new PropertyReflection ( $ propertyTag [ 1 ] , $ class -> getLine ( ) ) ; $ property -> setDocComment ( $ propertyTag [ 2 ] ) ; $ property -> setSho... | Adds a new property to the class using an array of tokens . |
36,517 | private function getTree ( Project $ project ) { $ key = $ project -> getBuildDir ( ) ; if ( ! isset ( $ this -> cachedTree [ $ key ] ) ) { $ this -> cachedTree [ $ key ] = $ this -> tree -> getTree ( $ project ) ; } return $ this -> cachedTree [ $ key ] ; } | Get tree for the given project . |
36,518 | public function installHook ( string $ hook , bool $ ask ) { $ doIt = true ; if ( $ ask ) { $ answer = $ this -> io -> ask ( ' <info>Install \'' . $ hook . '\' hook?</info> <comment>[y,n]</comment> ' , 'y' ) ; $ doIt = IOUtil :: answerToBool ( $ answer ) ; } if ( $ doIt ) { $ this -> writeHookFile ( $ hook ) ; } } | Install given hook |
36,519 | protected function getHookSourceCode ( string $ hook ) : string { $ absRepoPath = realpath ( $ this -> repository -> getRoot ( ) ) ; $ vendorPath = getcwd ( ) . '/vendor' ; $ configPath = realpath ( $ this -> config -> getPath ( ) ) ; return Template :: getCode ( $ hook , $ absRepoPath , $ vendorPath , $ configPath ) ;... | Return the source code for a given hook script |
36,520 | protected function needInstallConfirmation ( string $ hook ) : bool { return $ this -> repository -> hookExists ( $ hook ) && ! $ this -> force ; } | If the hook already exists the user has to confirm the installation |
36,521 | private function validateXml ( ) : void { if ( ! isset ( $ this -> xml -> project ) || ! isset ( $ this -> xml -> project -> metrics ) ) { throw new RuntimeException ( 'invalid clover xml file' ) ; } } | Make sure you have a valid xml structure |
36,522 | public function getCoverage ( ) : float { $ statements = ( string ) $ this -> xml -> project -> metrics -> attributes ( ) -> statements ; $ covered = ( string ) $ this -> xml -> project -> metrics -> attributes ( ) -> coveredstatements ; if ( $ statements < 1 || ! is_numeric ( $ covered ) ) { throw new RuntimeException... | Return test coverage in percent . |
36,523 | public function doesConditionApply ( Config \ Condition $ config ) : bool { $ condition = $ this -> createCondition ( $ config ) ; return $ condition -> isTrue ( $ this -> io , $ this -> repository ) ; } | Creates the configured condition and evaluates it |
36,524 | private function createCondition ( Config \ Condition $ config ) : ConditionInterface { if ( Util :: getExecType ( $ config -> getExec ( ) ) === 'cli' ) { return new Cli ( new Processor ( ) , $ config -> getExec ( ) ) ; } $ class = $ config -> getExec ( ) ; if ( ! class_exists ( $ class ) ) { throw new RuntimeException... | Return the configured condition |
36,525 | protected function getChangedFiles ( IO $ io , Repository $ repository ) { $ oldHash = $ io -> getArgument ( 'previousHead' , 'HEAD@{1}' ) ; $ newHash = $ io -> getArgument ( 'newHead' , 'HEAD' ) ; return $ repository -> getDiffOperator ( ) -> getChangedFiles ( $ oldHash , $ newHash ) ; } | Use diff - tree to find the changed files after this merge or checkout |
36,526 | protected function getRegex ( Config \ Options $ options ) : string { $ regex = $ options -> get ( 'regex' ) ; if ( empty ( $ regex ) ) { throw new ActionFailed ( 'No regex option' ) ; } return $ regex ; } | Extract regex from options array |
36,527 | protected function validate ( RuleBook $ ruleBook , Repository $ repository , IO $ io ) : void { if ( $ repository -> isMerging ( ) ) { return ; } $ problems = $ ruleBook -> validate ( $ repository -> getCommitMsg ( ) ) ; if ( count ( $ problems ) ) { $ io -> writeError ( $ this -> getErrorOutput ( $ problems , $ repos... | Validate the message |
36,528 | private function getErrorOutput ( array $ problems , Repository $ repository ) : string { $ err = count ( $ problems ) ; $ head = [ IOUtil :: getLineSeparator ( 80 , '-' ) , 'CAPTAINHOOK FOUND ' . $ err . ' PROBLEM' . ( $ err === 1 ? '' : 'S' ) . ' IN YOUR COMMIT MESSAGE' , IOUtil :: getLineSeparator ( 80 , '-' ) ] ; $... | Format the error output |
36,529 | private function formatProblem ( string $ problem ) : string { $ lines = explode ( PHP_EOL , $ problem ) ; $ amount = count ( $ lines ) ; for ( $ i = 1 ; $ i < $ amount ; $ i ++ ) { $ lines [ $ i ] = ' ' . $ lines [ $ i ] ; } return implode ( PHP_EOL , $ lines ) ; } | Indent multi line problems so the lines after the first one are indented for better readability |
36,530 | public function createConfig ( $ path = '' ) : Config { $ path = $ path ? : getcwd ( ) . DIRECTORY_SEPARATOR . CH :: CONFIG ; $ json = new Json ( $ path ) ; $ fileExists = $ json -> exists ( ) ; $ config = new Config ( $ path , $ fileExists ) ; if ( $ fileExists ) { $ this -> configure ( $ config , $ json -> readAssoc ... | Create a CaptainHook configuration |
36,531 | protected function configure ( Config $ config , array $ json ) : void { Util :: validateJsonConfiguration ( $ json ) ; foreach ( HookUtil :: getValidHooks ( ) as $ hook => $ class ) { if ( isset ( $ json [ $ hook ] ) ) { $ this -> configureHook ( $ config -> getHookConfig ( $ hook ) , $ json [ $ hook ] ) ; } } } | Initialize the configuration with data load from config file |
36,532 | protected function configureHook ( Config \ Hook $ config , array $ json ) : void { $ config -> setEnabled ( $ json [ 'enabled' ] ) ; foreach ( $ json [ 'actions' ] as $ actionJson ) { $ options = isset ( $ actionJson [ 'options' ] ) && is_array ( $ actionJson [ 'options' ] ) ? $ actionJson [ 'options' ] : [ ] ; $ cond... | Setup a hook configuration by json data |
36,533 | protected function getArgumentOutput ( array $ args ) : string { $ out = ' Original arguments:' . PHP_EOL ; foreach ( $ args as $ name => $ value ) { $ out .= ' ' . $ name . ' => <comment>' . $ value . '</comment>' . PHP_EOL ; } return $ out ; } | Format output to display original hook arguments |
36,534 | public function isTrue ( IO $ io , Repository $ repository ) : bool { return $ this -> didAnyFileChange ( $ this -> getChangedFiles ( $ io , $ repository ) ) ; } | Evaluates the condition |
36,535 | private function didAnyFileChange ( array $ changedFiles ) : bool { foreach ( $ this -> filesToWatch as $ file ) { if ( in_array ( $ file , $ changedFiles ) ) { return true ; } } return false ; } | Check if any of the configured files was changed within the applied change set |
36,536 | public function configureHooks ( Config $ config ) : void { $ msgHook = $ config -> getHookConfig ( Hooks :: COMMIT_MSG ) ; $ preHook = $ config -> getHookConfig ( Hooks :: PRE_COMMIT ) ; $ msgHook -> setEnabled ( true ) ; $ preHook -> setEnabled ( true ) ; $ this -> setupMessageHook ( $ msgHook ) ; $ this -> setupPHPL... | Setup hooks by asking some basic questions |
36,537 | private function setupMessageHook ( Config \ Hook $ config ) : void { $ answer = $ this -> io -> ask ( ' <info>Do you want to validate your commit messages?</info> <comment>[y,n]</comment> ' , 'n' ) ; if ( IOUtil :: answerToBool ( $ answer ) ) { $ call = '\\CaptainHook\\App\\Hook\\Message\\Action\\Beams' ; $ options =... | Setup the commit message hook |
36,538 | public static function getHookCommand ( string $ hook ) : string { if ( ! self :: isValid ( $ hook ) ) { throw new RuntimeException ( sprintf ( 'Hook \'%s\' is not supported' , $ hook ) ) ; } return Hooks :: getValidHooks ( ) [ $ hook ] ; } | Returns hooks command class |
36,539 | public function beforeHook ( ) : void { $ this -> commentChar = $ this -> repository -> getConfigOperator ( ) -> getSafely ( 'core.commentchar' , '#' ) ; $ this -> file = ( string ) $ this -> arguments -> get ( 'file' ) ; $ this -> mode = ( string ) $ this -> arguments -> get ( 'mode' ) ; $ this -> hash = ( string ) $ ... | Fetch the original hook arguments and message related config settings |
36,540 | public function afterAction ( ) : void { file_put_contents ( $ this -> file , $ this -> repository -> getCommitMsg ( ) -> getRawContent ( ) ) ; parent :: afterAction ( ) ; } | Write the commit message to disk so git or the next action can proceed further |
36,541 | public function getIO ( InputInterface $ input , OutputInterface $ output ) : IO { if ( null === $ this -> io ) { $ this -> io = new IO \ DefaultIO ( $ input , $ output , $ this -> getHelperSet ( ) ) ; } return $ this -> io ; } | IO interface getter |
36,542 | protected function getConfig ( string $ path = '' , bool $ failIfNotFound = false ) : Config { $ this -> config = Config \ Factory :: create ( $ path ) ; if ( $ failIfNotFound && ! $ this -> config -> isLoadedFromFile ( ) ) { throw new \ RuntimeException ( 'Please create a captainhook configuration first' . PHP_EOL . '... | CaptainHook config getter |
36,543 | public static function getValidHooks ( ) : array { return [ self :: COMMIT_MSG => 'CommitMsg' , self :: PRE_PUSH => 'PrePush' , self :: PRE_COMMIT => 'PreCommit' , self :: PREPARE_COMMIT_MSG => 'PrepareCommitMsg' , self :: POST_COMMIT => 'PostCommit' , self :: POST_MERGE => 'PostMerge' , self :: POST_CHECKOUT => 'PostC... | Returns the list of valid hooks |
36,544 | private function doWrite ( $ messages , $ newline , $ stderr , $ verbosity ) { $ sfVerbosity = $ this -> verbosityMap [ $ verbosity ] ; if ( $ sfVerbosity > $ this -> output -> getVerbosity ( ) ) { return ; } $ this -> getOutputToWriteTo ( $ stderr ) -> write ( $ messages , $ newline , $ sfVerbosity ) ; } | Write to the appropriate user output |
36,545 | private function getOutputToWriteTo ( $ stdErr = false ) { if ( $ stdErr && $ this -> output instanceof ConsoleOutputInterface ) { return $ this -> output -> getErrorOutput ( ) ; } return $ this -> output ; } | Return the output to write to |
36,546 | public function getJsonData ( ) : array { $ config = [ 'enabled' => $ this -> isEnabled , 'actions' => [ ] ] ; foreach ( $ this -> actions as $ action ) { $ config [ 'actions' ] [ ] = $ action -> getJsonData ( ) ; } return $ config ; } | Return config data |
36,547 | protected function formatCommand ( string $ command , array $ args ) : string { foreach ( $ args as $ key => $ value ) { $ command = str_replace ( '{' . strtoupper ( $ key ) . '}' , $ value , $ command ) ; } return $ command ; } | Replace argument placeholder with their original values |
36,548 | public static function getCode ( string $ hook , string $ repoPath , string $ vendorPath , string $ configPath ) : string { $ tplVendorPath = self :: getTplTargetPath ( $ repoPath , $ vendorPath ) ; $ tplConfigPath = self :: getTplTargetPath ( $ repoPath , $ configPath ) ; return '#!/usr/bin/env php' . PHP_EOL . '<?php... | Return the php code for the git hook scripts . |
36,549 | public function pass ( CommitMessage $ msg ) : bool { return $ this -> isSubjectValid ( $ msg ) && $ this -> isBodyValid ( $ msg ) ; } | Check if the message contains blacklisted words |
36,550 | protected function isSubjectValid ( CommitMessage $ msg ) : bool { return ! $ this -> containsBlacklistedWord ( $ this -> blacklist [ 'subject' ] , $ msg -> getSubject ( ) ) ; } | Check commit message subject for blacklisted words |
36,551 | protected function isBodyValid ( CommitMessage $ msg ) : bool { return ! $ this -> containsBlacklistedWord ( $ this -> blacklist [ 'body' ] , $ msg -> getBody ( ) ) ; } | Check commit message body for blacklisted words |
36,552 | protected function containsBlacklistedWord ( array $ list , string $ content ) : bool { if ( ! $ this -> isCaseSensitive ) { $ content = strtolower ( $ content ) ; $ list = array_map ( 'strtolower' , $ list ) ; } foreach ( $ list as $ term ) { if ( strpos ( $ content , $ term ) !== false ) { $ this -> hint .= PHP_EOL .... | Contains blacklisted word |
36,553 | protected function hasSyntaxErrors ( $ file ) : bool { $ process = new Processor ( ) ; $ result = $ process -> run ( 'php -l ' . escapeshellarg ( $ file ) ) ; return ! $ result -> isSuccessful ( ) ; } | Lint a php file |
36,554 | public function read ( bool $ assoc = false ) { $ json = json_decode ( parent :: read ( ) , $ assoc ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new RuntimeException ( 'Invalid json file' ) ; } return $ json ; } | Read and decode the json file |
36,555 | public function write ( $ content , $ options = 448 ) : void { $ json = json_encode ( $ content , $ options ) . ( $ options & JSON_PRETTY_PRINT ? "\n" : '' ) ; parent :: write ( $ json ) ; } | Encode content to json and write to disk |
36,556 | public function execute ( Config $ config , IO $ io , Repository $ repository , Config \ Action $ action ) : void { $ class = $ action -> getAction ( ) ; try { if ( $ this -> isStaticMethodCall ( $ class ) ) { $ io -> write ( $ this -> executeStatic ( $ class ) ) ; } else { $ exe = $ this -> createAction ( $ class ) ; ... | Execute the configured action . |
36,557 | protected function executeStatic ( string $ class ) : string { list ( $ class , $ method ) = explode ( '::' , $ class ) ; if ( ! class_exists ( $ class ) ) { throw new \ RuntimeException ( 'could not find class: ' . $ class ) ; } if ( ! method_exists ( $ class , $ method ) ) { throw new \ RuntimeException ( 'could not ... | Execute static method call and return its output . |
36,558 | public static function beams ( int $ subjectLength = 50 , int $ bodyLineLength = 72 ) : array { return [ new Rule \ CapitalizeSubject ( ) , new Rule \ LimitSubjectLength ( $ subjectLength ) , new Rule \ NoPeriodOnSubjectEnd ( ) , new Rule \ UseImperativeMood ( ) , new Rule \ LimitBodyLineLength ( $ bodyLineLength ) , n... | Return Beams rule set |
36,559 | protected function getDefaultCommands ( ) : array { return [ new Cmd \ Help ( ) , new Cmd \ Install ( ) , new Cmd \ Configuration ( ) , new Cmd \ Add ( ) , new Cmd \ Disable ( ) , new Cmd \ Enable ( ) , new Cmd \ Run ( ) , ] ; } | Initializes all the CaptainHook commands . |
36,560 | public static function isSubDirectoryOf ( array $ subDir , array $ parentDir ) : bool { foreach ( $ parentDir as $ index => $ dir ) { if ( ! isset ( $ subDir [ $ index ] ) || $ dir !== $ subDir [ $ index ] ) { return false ; } } return true ; } | Is the given subDir a sub directory of given parentDir . |
36,561 | public static function getSubPathOf ( array $ subDir , array $ parentDir ) : string { if ( ! self :: isSubDirectoryOf ( $ subDir , $ parentDir ) ) { throw new \ RuntimeException ( 'Invalid sub directory' ) ; } $ path = [ ] ; foreach ( array_slice ( $ subDir , count ( $ parentDir ) ) as $ dir ) { $ path [ ] = $ dir ; } ... | Return the relative path from parentDir to subDir . |
36,562 | public function validate ( CommitMessage $ msg ) : array { $ problems = [ ] ; foreach ( $ this -> rules as $ rule ) { if ( ! $ rule -> pass ( $ msg ) ) { $ problems [ ] = $ rule -> getHint ( ) ; } } return $ problems ; } | Validates all rules |
36,563 | public function getHookConfig ( string $ hook ) : Config \ Hook { if ( ! Hook \ Util :: isValid ( $ hook ) ) { throw new \ InvalidArgumentException ( 'Invalid hook name: ' . $ hook ) ; } return $ this -> hooks [ $ hook ] ; } | Return config for given hook . |
36,564 | public function getJsonData ( ) : array { $ return = [ ] ; foreach ( Hooks :: getValidHooks ( ) as $ hook => $ value ) { $ return [ $ hook ] = $ this -> hooks [ $ hook ] -> getJsonData ( ) ; } return $ return ; } | Return config array to write to disc . |
36,565 | public function applyTo ( Config $ config ) { $ hookConfig = $ config -> getHookConfig ( $ this -> hookToChange ) ; $ setup = new Advanced ( $ this -> io ) ; $ actionConfig = $ setup -> getActionConfig ( ) ; $ hookConfig -> addAction ( $ actionConfig ) ; } | Apply changes to the given config |
36,566 | public static function validateJsonConfiguration ( array $ json ) : void { foreach ( HookUtil :: getValidHooks ( ) as $ hook => $ class ) { if ( isset ( $ json [ $ hook ] ) ) { self :: validateHookConfig ( $ json [ $ hook ] ) ; } } } | Validate a configuration |
36,567 | public static function validateHookConfig ( array $ json ) : void { if ( ! self :: keysExist ( [ 'enabled' , 'actions' ] , $ json ) ) { throw new \ RuntimeException ( 'Config error: invalid hook configuration' ) ; } if ( ! is_array ( $ json [ 'actions' ] ) ) { throw new \ RuntimeException ( 'Config error: \'actions\' m... | Validate a hook configuration |
36,568 | public static function validateActionsConfig ( array $ json ) : void { foreach ( $ json as $ action ) { if ( ! self :: keysExist ( [ 'action' ] , $ action ) ) { throw new \ RuntimeException ( 'Config error: \'action\' missing' ) ; } if ( empty ( $ action [ 'action' ] ) ) { throw new \ RuntimeException ( 'Config error: ... | Validate a list of action configurations |
36,569 | public static function validateConditionsConfig ( array $ json ) : void { foreach ( $ json as $ condition ) { if ( ! self :: keysExist ( [ 'exec' ] , $ condition ) || empty ( $ condition [ 'exec' ] ) ) { throw new \ RuntimeException ( 'Config error: \'exec\' is required for conditions' ) ; } if ( ! empty ( $ condition ... | Validate a list of condition configurations |
36,570 | public static function writeToDisk ( Config $ config ) : void { $ filePath = $ config -> getPath ( ) ; $ file = new Json ( $ filePath ) ; $ file -> write ( $ config -> getJsonData ( ) ) ; } | Write the config to disk |
36,571 | private static function keysExist ( array $ keys , array $ subject ) : bool { foreach ( $ keys as $ key ) { if ( ! isset ( $ subject [ $ key ] ) ) { return false ; } } return true ; } | Does an array have the expected keys |
36,572 | public function configureHooks ( Config $ config ) : void { foreach ( HookUtil :: getHooks ( ) as $ hook ) { $ this -> configureHook ( $ config -> getHookConfig ( $ hook ) , $ hook ) ; } } | Setup hook configurations by asking some questions |
36,573 | public function configureHook ( Config \ Hook $ config , string $ name ) : void { $ answer = $ this -> io -> ask ( ' <info>Enable \'' . $ name . '\' hook?</info> <comment>[y,n]</comment> ' , 'n' ) ; $ enable = IOUtil :: answerToBool ( $ answer ) ; $ config -> setEnabled ( $ enable ) ; if ( $ enable ) { $ addAction = $... | Configure a hook by asking some questions |
36,574 | public function getActionConfig ( ) : Config \ Action { $ call = $ this -> io -> ask ( ' <info>PHP class or shell command to execute?</info> ' ) ; $ options = $ this -> getActionOptions ( RunnerUtil :: getExecType ( $ call ) ) ; return new Config \ Action ( $ call , $ options ) ; } | Setup a action config with user input |
36,575 | protected function getPHPActionOptions ( ) : array { $ options = [ ] ; $ addOption = $ this -> io -> ask ( ' <info>Add a validator option?</info> <comment>[y,n]</comment> ' , 'n' ) ; while ( IOUtil :: answerToBool ( $ addOption ) ) { $ options = array_merge ( $ options , $ this -> getPHPActionOption ( ) ) ; $ addOptio... | Get the php action options |
36,576 | protected function getPHPActionOption ( ) : array { $ result = [ ] ; $ answer = $ this -> io -> askAndValidate ( ' <info>Specify options key and value</info> <comment>[key:value]</comment> ' , [ '\\CaptainHook\\App\\Runner\\Config\\Setup\\Guided' , 'isPHPActionOptionValid' ] , 3 , null ) ; if ( null !== $ answer ) { l... | Ask the user for a php action option |
36,577 | private function getLockFileHash ( string $ path ) : string { $ lockFile = json_decode ( $ this -> loadFile ( $ path . DIRECTORY_SEPARATOR . 'composer.lock' ) ) ; $ hashKey = 'content-hash' ; if ( ! isset ( $ lockFile -> $ hashKey ) ) { throw new \ Exception ( 'could not find content hash, please update composer to the... | Read the composer . lock file and extract the composer . json hash |
36,578 | private function getConfigFileHash ( string $ path ) : string { $ content = json_decode ( $ this -> loadFile ( $ path . DIRECTORY_SEPARATOR . 'composer.json' ) , true ) ; $ relevantContent = [ ] ; foreach ( array_intersect ( $ this -> relevantKeys , array_keys ( $ content ) ) as $ key ) { $ relevantContent [ $ key ] = ... | Read the composer . json file and create a md5 hash on its relevant content |
36,579 | private function loadFile ( string $ file ) : string { if ( ! file_exists ( $ file ) ) { throw new \ Exception ( $ file . ' not found' ) ; } return ( string ) file_get_contents ( $ file ) ; } | Load a composer file |
36,580 | public static function setup ( Event $ event ) : void { $ extra = self :: getExtraConfig ( $ event ) ; $ config = self :: extract ( CH :: COMPOSER_CONFIG , $ extra , CH :: CONFIG ) ; $ repo = self :: extract ( CH :: COMPOSER_GIT_DIR , $ extra , '.git' ) ; $ app = self :: createApplication ( $ event -> getIO ( ) , $ con... | Gets called by composer after a successful package installation |
36,581 | private static function install ( Application $ app , string $ config , string $ repo ) : void { $ options = [ 'command' => 'install' , '--configuration' => $ config , '--git-directory' => $ repo , '-f' => '-f' ] ; $ app -> run ( new ArrayInput ( $ options ) ) ; } | Installs the hooks to your local repository |
36,582 | private static function getExtraConfig ( Event $ event ) : array { $ extra = $ event -> getComposer ( ) -> getPackage ( ) -> getExtra ( ) ; return is_array ( $ extra ) ? $ extra : [ ] ; } | Return Composer extra config make sure it is an array |
36,583 | private static function createApplication ( IOInterface $ io , string $ config ) : Application { $ app = new Application ( ) ; $ app -> setAutoExit ( false ) ; $ app -> setConfigFile ( $ config ) ; $ app -> setProxyIO ( $ io ) ; $ install = new Install ( ) ; $ install -> setIO ( $ app -> getIO ( ) ) ; $ app -> add ( $ ... | Create a CaptainHook Composer application |
36,584 | public function getRepositoryPath ( ) : string { if ( empty ( $ this -> repositoryPath ) ) { $ this -> repositoryPath = ( string ) getcwd ( ) ; } return $ this -> repositoryPath ; } | Get the git repository root path |
36,585 | public function setHook ( string $ hook ) : Hook { if ( ! Util :: isValid ( $ hook ) ) { throw new \ RuntimeException ( 'Invalid hook name' ) ; } $ this -> hookToExecute = $ hook ; return $ this ; } | Set the hook to execute |
36,586 | private function createCommand ( ) : Command \ Hook { $ class = '\\CaptainHook\\App\\Console\\Command\\Hook\\' . Util :: getHookCommand ( $ this -> hookToExecute ) ; $ command = new $ class ( $ this -> getConfigFile ( ) , $ this -> getRepositoryPath ( ) ) ; $ command -> setHelperSet ( $ this -> getHelperSet ( ) ) ; ret... | Create the hook command |
36,587 | public function run ( ) : void { $ hookConfig = $ this -> config -> getHookConfig ( $ this -> hook ) ; $ actions = $ hookConfig -> getActions ( ) ; if ( ! $ hookConfig -> isEnabled ( ) ) { $ this -> io -> write ( $ this -> formatHookHeadline ( 'Skip' ) ) ; return ; } if ( count ( $ actions ) === 0 ) { $ this -> io -> w... | Execute the hook and all its actions |
36,588 | protected function handleAction ( Config \ Action $ action ) : void { $ this -> io -> write ( [ '' , 'Action: <comment>' . $ action -> getAction ( ) . '</comment>' ] ) ; if ( ! $ this -> doConditionsApply ( $ action -> getConditions ( ) ) ) { $ this -> io -> write ( [ '' , 'Skipped due to failing conditions' ] ) ; retu... | Executes a configured hook action |
36,589 | protected function executePhpAction ( Config \ Action $ action ) : void { $ this -> beforeAction ( ) ; $ runner = new Action \ PHP ( ) ; $ runner -> execute ( $ this -> config , $ this -> io , $ this -> repository , $ action ) ; $ this -> afterAction ( ) ; } | Execute a php hook action |
36,590 | protected function executeCliAction ( Config \ Action $ action ) : void { $ runner = new Action \ Cli ( ) ; $ runner -> execute ( $ this -> io , $ action , $ this -> arguments ) ; } | Execute a cli hook action |
36,591 | public static function getExecMethod ( string $ type ) : string { $ valid = [ 'php' => 'executePhpAction' , 'cli' => 'executeCliAction' ] ; if ( ! isset ( $ valid [ $ type ] ) ) { throw new RuntimeException ( 'invalid action type: ' . $ type ) ; } return $ valid [ $ type ] ; } | Return the right method name to execute an action |
36,592 | private function doConditionsApply ( array $ conditions ) : bool { $ conditionRunner = new Condition ( $ this -> io , $ this -> repository ) ; foreach ( $ conditions as $ config ) { if ( ! $ conditionRunner -> doesConditionApply ( $ config ) ) { return false ; } } return true ; } | Check if conditions apply |
36,593 | private function formatHookHeadline ( string $ mode ) : array { $ headline = ' ' . $ mode . ' hook: <comment>' . $ this -> hook . '</comment> ' ; return [ '' , IOUtil :: getLineSeparator ( 8 ) . $ headline . IOUtil :: getLineSeparator ( 80 - 8 - strlen ( strip_tags ( $ headline ) ) ) ] ; } | Some fancy output formatting |
36,594 | public function setHook ( string $ hook ) : Editor { if ( ! Util :: isValid ( $ hook ) ) { throw new Exception \ InvalidHookName ( 'Invalid hook name \'' . $ hook . '\'' ) ; } $ this -> hookToEdit = $ hook ; return $ this ; } | Set the hook that should be changed |
36,595 | public function run ( ) : void { if ( ! $ this -> config -> isLoadedFromFile ( ) ) { throw new \ RuntimeException ( 'No configuration to edit' ) ; } $ this -> checkHook ( ) ; $ this -> checkChange ( ) ; $ change = $ this -> createChange ( ) ; $ change -> applyTo ( $ this -> config ) ; Config \ Util :: writeToDisk ( $ t... | Executes the Runner |
36,596 | private function createChange ( ) : Change { $ changeClass = '\\CaptainHook\\App\\Runner\\Config\\Change\\' . $ this -> change ; if ( ! class_exists ( $ changeClass ) ) { throw new \ RuntimeException ( 'Invalid change requested' ) ; } return new $ changeClass ( $ this -> io , $ this -> hookToEdit ) ; } | Create an config edit command |
36,597 | public function read ( ) { $ old = libxml_use_internal_errors ( true ) ; $ xml = simplexml_load_file ( $ this -> path ) ; $ errors = libxml_get_errors ( ) ; libxml_use_internal_errors ( $ old ) ; if ( count ( $ errors ) ) { throw new \ RuntimeException ( 'xml file \'' . $ this -> path . '\': ' . $ errors [ 0 ] -> messa... | Read the xml file and return a SimpleXML object . |
36,598 | public function pass ( CommitMessage $ msg ) : bool { $ subjectLength = strlen ( $ msg -> getSubject ( ) ) ; if ( $ subjectLength > $ this -> maxLength ) { $ this -> hint .= ' (' . $ subjectLength . ')' ; return false ; } return true ; } | Check if commit message doesn t exceeed the max length |
36,599 | private function checkDir ( ) : void { $ dir = dirname ( $ this -> path ) ; if ( ! is_dir ( $ dir ) ) { if ( file_exists ( $ dir ) ) { throw new \ RuntimeException ( $ dir . ' exists and is not a directory.' ) ; } if ( ! @ mkdir ( $ dir , 0755 , true ) ) { throw new \ RuntimeException ( $ dir . ' does not exist and cou... | Create directory if necessary |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.