mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 09:19:40 +01:00
Cleanup
This commit is contained in:
parent
79d2e25084
commit
bc608ffb45
@ -1046,10 +1046,6 @@ class InstancePropertyAssignmentAnalyzer
|
||||
),
|
||||
$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;
|
||||
}
|
||||
} else {
|
||||
|
@ -1297,6 +1297,7 @@ class AssignmentAnalyzer
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$var_id = ExpressionIdentifier::getVarId(
|
||||
$stmt,
|
||||
$statements_analyzer->getFQCLN(),
|
||||
|
@ -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)
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue
Block a user