diff --git a/Puc/v4/BitBucket/Api.php b/Puc/v4/BitBucket/Api.php index 591f8ff..c7c4a46 100644 --- a/Puc/v4/BitBucket/Api.php +++ b/Puc/v4/BitBucket/Api.php @@ -115,23 +115,6 @@ if ( !class_exists('Puc_v4_BitBucket_Api', false) ): return isset($tag->name) && $this->looksLikeVersion($tag->name); } - /** - * Compare two BitBucket tags as if they were version number. - * - * @param stdClass $tag1 - * @param stdClass $tag2 - * @return int - */ - protected function compareTagNames($tag1, $tag2) { - if ( !isset($tag1->name) ) { - return 1; - } - if ( !isset($tag2->name) ) { - return -1; - } - return -version_compare(ltrim($tag1->name, 'v'), ltrim($tag2->name, 'v')); - } - /** * Get the contents of a file from a specific branch or tag. * diff --git a/Puc/v4/GitHub/Api.php b/Puc/v4/GitHub/Api.php index 31682fe..2dc3558 100644 --- a/Puc/v4/GitHub/Api.php +++ b/Puc/v4/GitHub/Api.php @@ -86,23 +86,6 @@ if ( !class_exists('Puc_v4_GitHub_Api', false) ): )); } - /** - * Compare two GitHub tags as if they were version number. - * - * @param string $tag1 - * @param string $tag2 - * @return int - */ - protected function compareTagNames($tag1, $tag2) { - if ( !isset($tag1->name) ) { - return 1; - } - if ( !isset($tag2->name) ) { - return -1; - } - return -version_compare($tag1->name, $tag2->name); - } - /** * Get a branch by name. * diff --git a/Puc/v4/VcsApi.php b/Puc/v4/VcsApi.php index d9a9a96..ecfafff 100644 --- a/Puc/v4/VcsApi.php +++ b/Puc/v4/VcsApi.php @@ -2,6 +2,8 @@ if ( !class_exists('Puc_v4_VcsApi') ): abstract class Puc_v4_VcsApi { + protected $tagNameProperty = 'name'; + /** * Get the readme.txt file from the remote repository and parse it * according to the plugin readme standard. @@ -63,20 +65,21 @@ if ( !class_exists('Puc_v4_VcsApi') ): } /** - * Compare two tag names as if they were version number. + * Compare two tags as if they were version number. * - * @param string $tag1 - * @param string $tag2 + * @param stdClass $tag1 Tag object. + * @param stdClass $tag2 Another tag object. * @return int */ protected function compareTagNames($tag1, $tag2) { - if ( !isset($tag1) ) { + $property = $this->tagNameProperty; + if ( !isset($tag1->$property) ) { return 1; } - if ( !isset($tag2) ) { + if ( !isset($tag2->$property) ) { return -1; } - return -version_compare(ltrim($tag1, 'v'), ltrim($tag2, 'v')); + return -version_compare(ltrim($tag1->$property, 'v'), ltrim($tag2->$property, 'v')); } /** @@ -114,6 +117,7 @@ if ( !class_exists('Puc_v4_VcsApi') ): return null; } + /** @noinspection PhpUndefinedClassInspection */ return Parsedown::instance()->text($changelog); }