smarty-php / smarty-php/smarty
Incorrect type on Source->timestamp
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.3k
- Forks
- 709
- PR merge metrics
- No merged PRs in 30d
Description
The PHPDoc type for the field $timestamp is set as int in Smarty\Template\Source, however there are many examples that exist which set the timestamp to false in the event that there is no source file found.
Here are some notable examples:
public function populate(\Smarty\Template\Source $source, \Smarty\Template $_template = null)
{
$source->uid = sha1($source->name);
$source->timestamp = $source->exists = true;
}
public function populate(Source $source, ?Template $_template = null) {
$source->uid = false;
$source->content = $this->getContent($source);
$source->timestamp = $source->exists = !!$source->content;
}
public function populate(Source $source, ?Template $_template = null) {
$source->uid = sha1(
$source->name . ($source->isConfig ? $source->getSmarty()->_joined_config_dir :
$source->getSmarty()->_joined_template_dir)
);
if ($path = $this->getFilePath($source->name, $source->getSmarty(), $source->isConfig)) {
if (isset($source->getSmarty()->security_policy) && is_object($source->getSmarty()->security_policy)) {
$source->getSmarty()->security_policy->isTrustedResourceDir($path, $source->isConfig);
}
$source->exists = true;
$source->timestamp = filemtime($path);
} else {
$source->timestamp = $source->exists = false;
}
}
If this is intended, the type should likely be changed to int|false.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect the PHPDoc for $timestamp in Smarty\Template\Source and compare it with the populate methods in src/Resource/StringEval, src/Resource/StreamPlugin, and src/Resource/FilePlugin. Update the documented type if the false value is intended, then run the relevant existing test suite to verify the change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100