diff --git a/Puc/v4p9/Factory.php b/Puc/v4p9/Factory.php index ddcbf1c..599403c 100644 --- a/Puc/v4p9/Factory.php +++ b/Puc/v4p9/Factory.php @@ -19,13 +19,14 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): protected static $latestCompatibleVersion = ''; /** - * Wrapper method for buildUpdateChecker. + * A wrapper method for buildUpdateChecker() that reads the metadata URL from the plugin or theme header. * - * @param string $fullPath - * @param array + * @param string $fullPath Full path to the main plugin file or the theme's style.css. + * @param array $args Optional arguments. Keys should match the argument names of the buildUpdateChecker() method. + * @return Puc_v4p9_Plugin_UpdateChecker|Puc_v4p9_Theme_UpdateChecker|Puc_v4p9_Vcs_BaseChecker */ - public static function buildFromHeader( $fullPath, $args = array() ) { - $fullPath = self::normalizePath( $fullPath ); + public static function buildFromHeader($fullPath, $args = array()) { + $fullPath = self::normalizePath($fullPath); //Set up defaults. $defaults = array( @@ -35,15 +36,16 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): 'optionName' => '', 'muPluginFile' => '', ); - $args = array_merge( $defaults, array_intersect_key( $args, $defaults ) ); - extract( $args, EXTR_SKIP ); + $args = array_merge($defaults, array_intersect_key($args, $defaults)); + extract($args, EXTR_SKIP); //Check for the service URI - if ( empty( $metadataUrl ) ) { - $metadataUrl = self::getServiceURI( $fullPath ); + if ( empty($metadataUrl) ) { + $metadataUrl = self::getServiceURI($fullPath); } - return self::buildUpdateChecker( $metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile ); + /** @noinspection PhpUndefinedVariableInspection These variables are created by extract(), above. */ + return self::buildUpdateChecker($metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile); } /** @@ -212,28 +214,26 @@ if ( !class_exists('Puc_v4p9_Factory', false) ): * @param string $fullPath * @return string */ - private static function getServiceURI( $fullPath ) { + private static function getServiceURI($fullPath) { //Look for the URI - if ( is_readable( $fullPath ) ) { + if ( is_readable($fullPath) ) { $seek = array( 'github' => 'GitHub URI', 'gitlab' => 'GitLab URI', - 'bucket' => 'BitBucket URI' + 'bucket' => 'BitBucket URI', ); - $seek = apply_filters( 'puc_get_source_uri', $seek ); - $data = get_file_data( $fullPath, $seek ); - foreach( $data as $key => $uri ) { - if ( $uri ) return $uri; + $seek = apply_filters('puc_get_source_uri', $seek); + $data = get_file_data($fullPath, $seek); + foreach ($data as $key => $uri) { + if ( $uri ) { + return $uri; + } } } - //URI was not found so trigger an error. - trigger_error( - sprintf( - 'Unable to locate uri in header of "%s"', - htmlentities( $fullPath ) - ), - E_USER_ERROR + //URI was not found so throw an error. + throw new RuntimeException( + sprintf('Unable to locate URI in header of "%s"', htmlentities($fullPath)) ); }