Add docs and remove validity check on cache access

This commit is contained in:
Saul Johnson
2017-08-27 19:11:36 +01:00
parent 7a9910202c
commit 291e0497ce
3 changed files with 14 additions and 17 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ class CactusSmilesConverter extends SmilesConverter
$encoded = rawurlencode($name);
// Check if we've got the name cached already.
$cached = $this->getIfCachedAndValid($encoded);
$cached = $this->getIfCached($encoded);
if ($cached !== null) {
return $cached;
}
+12 -15
View File
@@ -47,17 +47,6 @@ abstract class SmilesConverter
return $this->db !== null;
}
/**
* Attempts to fix any errors in a SMILES string and returns the result.
*
* @param string $smiles the SMILES string to fix
* @return string the fixed SMILES string
*/
protected static function fixSmiles($smiles) {
$output = str_replace('|', '', $smiles); // Zap vertical bars.
return $output;
}
/**
* Returns true if a given SMILES string is valid, otherwise returns false.
*
@@ -69,19 +58,27 @@ abstract class SmilesConverter
}
/**
* @param $name
* @return string
* Returns a cached SMILES string from its corresponding compound name, if present.
*
* @param string $name the name of the compound to return
* @return string the SMILES structure of the compound, or null if not found
*/
protected function getIfCachedAndValid($name) {
protected function getIfCached($name) {
if ($this->isCacheEnabled()) {
$cachedSmiles = $this->db->get('smiles', 'name', $name);
if ($cachedSmiles !== null && self::isValidSmiles($cachedSmiles)) {
if ($cachedSmiles !== null) {
return $cachedSmiles;
}
}
return null;
}
/**
* Caches a compound name against its corresponding SMILES string.
*
* @param string $name the compound name
* @param string $smiles the corresponding SMILES string
*/
protected function cache($name, $smiles) {
if ($this->isCacheEnabled()) {
$this->db->insert(['name' => $name, 'smiles' => $smiles]); // Cache name for future.
+1 -1
View File
@@ -34,7 +34,7 @@ class WikipediaSmilesConverter extends SmilesConverter
$encoded = str_replace(' ', '_', $name);
// Check if we've got the name cached already.
$cached = $this->getIfCachedAndValid($encoded);
$cached = $this->getIfCached($encoded);
if ($cached !== null) {
return $cached;
}