1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00
This commit is contained in:
Olle 2020-06-23 17:25:31 +00:00
parent 79d2e25084
commit bc608ffb45
3 changed files with 1 additions and 99 deletions

View File

@ -1046,10 +1046,6 @@ class InstancePropertyAssignmentAnalyzer
), ),
$statements_analyzer->getSuppressedIssues() $statements_analyzer->getSuppressedIssues()
)) { )) {
//var_dump($context);
//$context->vars_in_scope['$this->t'] = new \Psalm\Type\Atomic\TNamedObject("Closed");
//die;
//throw new \Exception('here');
return false; return false;
} }
} else { } else {

View File

@ -1297,6 +1297,7 @@ class AssignmentAnalyzer
return; return;
} }
$var_id = ExpressionIdentifier::getVarId( $var_id = ExpressionIdentifier::getVarId(
$stmt, $stmt,
$statements_analyzer->getFQCLN(), $statements_analyzer->getFQCLN(),

View File

@ -1,95 +0,0 @@
<?php
// Examples: Query builder, file, socket.
interface ClosedFile
{
public function open();
}
interface OpenFile
{
public function read();
public function close();
}
interface CannotOpen {}
class MyFile implements ClosedFile, OpenFile, CannotOpen
{
/**
* @self-out ClosedFile
*/
public function __construct() {
}
/**
* @self-out OpenFile|CannotOpen
*/
public function open() {
// if can't open, throw exception and invalidate $this
}
/**
* @self-out ClosedFile
*/
public function close() {
}
/**
* @return string
*/
public function read() {
return 'content';
}
}
$file = new MyFile("somefile");
$file->open();
if ($file instanceof OpenFile) {
$content = $file->read();
$file->close();
} elseif ($file instanceof CannotOpen) {
// Mooo.
}
for ($i = 1; $i < 10; ++$i) {
// TODO: What here?
$file->open();
}
// ClosedFile
$file = new MyFile("somefile");
if ($file instanceof OpenFile) {
// TODO: Impossible
}
if (hardcomputation()) {
$file->open();
}
// $file is OpenFile|ClosedFile|CannotOpen
// TODO: Have to check state?
/**
* @param OpenFile $file
*/
function readall(OpenFile $file) {
$file->read();
$file->close(); // TODO: Not allowed to change state of aliased variable.
return $file; // TODO: Not allowed to transfer ownership
}
/**
* @param string $name
* @return ClosedFile
*/
function makefile($name) {
// ClosedFile
$file = new File($name);
dosomething($file); // Can't change state, still closed
return $file; // Owner can change
}
/**
* @param ClosedFile $file
* @param-out OpenFile $file
*/
function open(ClosedFile &$file)
{
}