Minor cleanup and formatting changes

This commit is contained in:
Yahnis Elsts 2020-03-31 17:52:07 +03:00
parent 0af94b5609
commit 949842cee6
1 changed files with 24 additions and 24 deletions

View File

@ -19,13 +19,14 @@ if ( !class_exists('Puc_v4p9_Factory', false) ):
protected static $latestCompatibleVersion = ''; 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 string $fullPath Full path to the main plugin file or the theme's style.css.
* @param array * @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() ) { public static function buildFromHeader($fullPath, $args = array()) {
$fullPath = self::normalizePath( $fullPath ); $fullPath = self::normalizePath($fullPath);
//Set up defaults. //Set up defaults.
$defaults = array( $defaults = array(
@ -35,15 +36,16 @@ if ( !class_exists('Puc_v4p9_Factory', false) ):
'optionName' => '', 'optionName' => '',
'muPluginFile' => '', 'muPluginFile' => '',
); );
$args = array_merge( $defaults, array_intersect_key( $args, $defaults ) ); $args = array_merge($defaults, array_intersect_key($args, $defaults));
extract( $args, EXTR_SKIP ); extract($args, EXTR_SKIP);
//Check for the service URI //Check for the service URI
if ( empty( $metadataUrl ) ) { if ( empty($metadataUrl) ) {
$metadataUrl = self::getServiceURI( $fullPath ); $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 * @param string $fullPath
* @return string * @return string
*/ */
private static function getServiceURI( $fullPath ) { private static function getServiceURI($fullPath) {
//Look for the URI //Look for the URI
if ( is_readable( $fullPath ) ) { if ( is_readable($fullPath) ) {
$seek = array( $seek = array(
'github' => 'GitHub URI', 'github' => 'GitHub URI',
'gitlab' => 'GitLab URI', 'gitlab' => 'GitLab URI',
'bucket' => 'BitBucket URI' 'bucket' => 'BitBucket URI',
); );
$seek = apply_filters( 'puc_get_source_uri', $seek ); $seek = apply_filters('puc_get_source_uri', $seek);
$data = get_file_data( $fullPath, $seek ); $data = get_file_data($fullPath, $seek);
foreach( $data as $key => $uri ) { foreach ($data as $key => $uri) {
if ( $uri ) return $uri; if ( $uri ) {
return $uri;
}
} }
} }
//URI was not found so trigger an error. //URI was not found so throw an error.
trigger_error( throw new RuntimeException(
sprintf( sprintf('Unable to locate URI in header of "%s"', htmlentities($fullPath))
'Unable to locate uri in header of "%s"',
htmlentities( $fullPath )
),
E_USER_ERROR
); );
} }