Simplify tag sorting.

We don't need two different implementation for GitHub and BitBucket, they use the same property name. But lets make the property configurable anyway in case other APIs do differ.
This commit is contained in:
Yahnis Elsts 2016-12-24 15:14:34 +02:00
parent 365792edde
commit f62a3d40fe
3 changed files with 10 additions and 40 deletions

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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);
}