Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/10/2015, 17:35
warbandit69
 
Fecha de Ingreso: diciembre-2008
Ubicación: http://www.solucionesrios.tk/
Mensajes: 413
Antigüedad: 15 años, 5 meses
Puntos: 19
Busqueda Como mejorar un codigo en Symfony y arreglar ciertos errores (Cajero Automatico)

Buenas tardes a todos, he hecho un ejercicio en Symfony simulando el comportamiento de un cajero automatico, dando la menor cantidad de billetes posibles, ya he realizado el codigo, sin embargo tengo algunos problemas.

1. Cuando intento arrojar una excepcion con este codigo

Código PHP:
if($residuo!=0)
        {
            throw new 
NoteUnavailableException('No puede ser entregada la cantidad ingresada'); //Error Here
            
return 0;
        } 
Me arroja este error

Código:
Attempted to load class "NoteUnavailableException" from namespace "AppBundle\Controller".
Did you forget a "use" statement for another namespace?

2. Al no ingresar la cantidad (dejarla nula) Ejemplo: /web/app_dev.php/Cashmachine/withdraw/ me sale el siguiente error:

Código:
No route found for "GET /Cashmachine/withdraw/"
404 Not Found - NotFoundHttpException
1 linked Exception:

    ResourceNotFoundException »
3. Por ultimo si saben como mejorar el codigo se los agradeceria

Aca el extracto completo

Código PHP:
namespace AppBundleController;

use 
SensioBundleFrameworkExtraBundleConfigurationRoute;
use 
SymfonyBundleFrameworkBundleControllerController;
use 
SymfonyComponentHttpFoundationRequest;
use 
SymfonyComponentHttpFoundationJsonResponse;
use 
SymfonyComponentSerializerExceptionInvalidArgumentException;
use 
SymfonyComponentHttpKernelExceptionNotFoundHttpException;

class 
CashmachineController extends Controller
{
    private  
$billetes = Array(100,50,20,10);

    
/**
     * @Route("/Cashmachine/withdraw/{cantidad}")
     **/
    
public function withdrawAction($cantidad null)
    {

        
//Creo arreglos vacios
        
$aEntregar = Array();
        
$data = array();

        
//Guardo la cantidad en un temporal
        
$tmpCantidad $cantidad;

        
//Si es negativo arrojo error
        
if($cantidad 0)
        {
            throw new 
InvalidArgumentException("Cantidad invalida");
            return 
0;
        }

        if ((
$cantidad == null) || ($cantidad ==0))
        {
            return new 
JsonResponse($data);
            return 
0;
        }

        
// Contador
        
$i 0;

        do
        {
            
$entero floor($cantidad/$this->billetes[$i]);
            
$residuo $cantidad%$this->billetes[$i];
            
array_push($aEntregar$entero);
            
$cantidad $residuo;
            
$i++;

        }
        while(
$residuo >= $this->billetes[count($this->billetes)-1] );

        if(
$residuo!=0)
        {
            throw new 
NoteUnavailableException('No puede ser entregada la cantidad ingresada'); //Error Here
            
return 0;
        }

        if(
count($aEntregar) < count($this->billetes))
        {
            do
            {
                
array_push($aEntregar0);
            }
            while(
count($aEntregar) < count($this->billetes));
        }

        for (
$j 0$j 4$j++)
        {
            
$tmpVar = ($aEntregar[$j] * $this->billetes[$j]);
            
$aEntregar[$j] = number_format($tmpVar2'.''');
        }

        
$data = array(
            
'La cantidad es' => $tmpCantidad,
            
'A entregar es' => $aEntregar
        
);

        
// calls json_encode and sets the Content-Type header
        
return new JsonResponse($data);
    }

__________________
http://www.solucionesrios.tk/

Visita mi Web!